欢迎光临散文网 会员登陆 & 注册

python笔记-1

2023-06-16 11:25 作者:littersho  | 我要投稿

print()函数的语法

print(“hello world”)--双引号 输出字符串,可直接在引号中打空格,个数不限   

输出 hello world

print(‘hello world--单引号 输出字符串   输出 hello world

print("""hello world

hello world

hello world

"""--一对三引号 输出多行文本   

 输出 

hello world

hello world

hello world

print(“hello”+"world")--+号连接两个字符串间没有空格 输出 helloworld

print(“hello”,"world")--两个字符串间可以用逗号间隔,输出空格 输出 hello world

print(“hello world”*3)  --输出 hello worldhello worldhello world

print(“hello world\n”*3)-- \n表示回车 输出 

hello world

hello world

hello world

print(“hello world”,end=“/”

print(“hello world”,end=“/”)-- 用end参数来设置结束符号 输出 

hello world/hello world/

输出数学表达式
print后的括号中如果是数学表达式,则打印结果为表达式最终运算的结果

print(5+3)或者直接输入 5+3     --输出 8

注释

Python中单行注释以 # 开头

多行注释可以用多个 # 号,或者 ''' 和 """

小练习:

print(“-----------------------来玩个小游戏吧-------------------------”)

temp= input("不妨猜一下我心中想的是哪个数字:”)

'''

input() 函数接受一个标准输入数据 

返回为 string 类型

'''

guess= int(temp)#一个=表示赋值

if guess==8:#两个=表示判断相等

    print("你是我肚里的蛔虫吗?)

    print("哼,猜中了也没有奖励!)

else:

    print("猜错了!)

print("游戏结束!)







python笔记-1的评论 (共 条)

分享到微博请遵守国家法律