# 1.注释
# 行注释 # # print('****') # 多行注释三个双引号或者单引号 '''print('****') print('****') .....''' |
# 2.打印(print)
# print函数可以在电脑上输出字符串等 print ( '*******' ) # *****代表任何字符串 输出的用双引号 “” 或者单引号 ' ' 包含起来 |
# 3.变量声明
# 1. name=value # 例如 acg = 18 print (acg) # example: 以追加的形似打印 name = 'liugege' print ( "my name is" ,name) # 2. var1=var2=var3=value # 3. var1,var2,var3=1,2,3 # example: name = 'liugege' print ( "my name is" ,name) |
# 4.用户输入
# 在python3中的输入为input() input()在我看来是c语言中的printf和scanf的相结合input()括号中单引号或者双引号内的内容会被先打印出来输入的 # 值将赋给变量 name = input ( "name:" ) job = input ( "job:" ) year = input ( "year:" ) print (name,job,uear) # 值得注意的是python中输入的值默认为字符串 若输入的是数字想将输入的值与数字比较需将输入的值强制转换成数字在比较 |
# 5.字符串代替输出
#1.追加 #追加谨记引号的使用 name = 'liugege' print ( "my name is" ,name) # 或者 下面'''****''' 为格式化打印 name = input ( "name:" ) name = input ( "name:" ) job = input ( "job:" ) year = input ( "year:" ) info = ''' Name:''' + name + ''' Job:''' + job + ''' year:''' + year print (info) # 2.%s代替 name = input ( "name:" ) job = input ( "job:" ) year = input ( "year:" ) info = ''' Name:%s Job:%s year:%s ''' % (name,job,year) print (info) #3. 另一种代替 name = input ( "name:" ) job = input ( "job:" ) year = input ( "year:" ) info = ''' Name:{name} Job:{jib} year:{year} ''' . format (_name = name,_job = job,_year = year) print (info) |
# 6. 强制转换
# 例如: name = int ( input ( "name:" )) #python默认字符串 |