name 通过逗号分隔;
常量的名字全部大写,其实可以修改;
# Author:Csicsi
print("hello world!")
name = "Csicsi"
name2 = name
print("My name is", name, name2)
name = "L"
print(name,name2)
friend_of_Csicsi = "S"
FriendOfCsicsi = "S"
HOME = "M"
print(FriendOfCsicsi, "lives in", HOME, "with", name, "and", name2)
ASCII 码 每个字符占一个字节,255,1bytes Unicode 每个字符占两个字节, UTF8 可变长的Unicode,英文字符按ascii码存,中文字符占3个字节 python2 不能直接写中文 python3 可以直接写中文
input 输入都是字符串,(是py2中的raw_input,py2中的input没有了) %s 字符串 %d 整数 %f 浮点数 info = ''' ---------------- info ---------------- Name : %s; Age : %s; job : %s; Salary : %s; ''' % (name, age, job, salary) print(info) info2 = ''' ---------------- info2 ---------------- Name : {_name} Age : {_age} job : {_job} Salary : {_salary} '''.format(_name=name, _age=age, _job=job, _salary=salary) info3 = ''' ----------------- info3 ----------------- Name : {0} Age : {1} job : {2} Salary : {3} '''.format(name, age, job, salary)
%s 代表 string, %d 表示只能输入数字,帮助检测数据类型
# Author:Csicsi
username = input("username:")
password = input("password:")
print(username,password)
name = input("Name:")
age = int(input("Age:"))
job = input("Job:")
salary = input("Salary:")
info = '''
------- info of ''' + name + ''' ---------
Age:''' + str(age) + '''
Job:''' + job + '''
Salary:''' + salary + '''
'''
print(info)
info2 = '''
------- info2 of %s ---------
Age:%d
Job:%s
Salary:%s
''' %(name,age,job,salary)
print(info2)
info3 = '''
------- info3 of {_name} ---------
Age:{_age}
Job:{_job}
Salary:{_salary}
'''.format(_name=name,
_age=age,
_job=job,
_salary=salary)
print(info3)
info4 = '''
------- info4 of {0} ---------
Age:{1}
Job:{2}
Salary:{3}
'''.format(name,age,job,salary)
print(info4)
“=”表示赋值,“==”表示等于 getpass在Pycharm里无法实现,在CMD里可以执行 【python的强制缩进】 - python 用 强制缩进 来代表结束语。 - INDENTATION ERROR代表缩进错误 - 所有的代码,如果自己就是顶级,就必须顶格写。
# Author: csicsi
import getpass
_username = 'csicsi'
_password = '1234'
username = input("username=")
#password = getpass.getpass("password")
password = input("password=")
if _username == username and _password == password:
print("Welcome user {name} login...".format(name=username))
else:
print("Invalid username or password!")
# Author: csicsi
age_of_csicsi = 23
count = 0
while count < 3:
guess_age = int(input("guess age:"))
if guess_age == age_of_csicsi:
print("You are a genius! csicsi is {age}.".format(age=guess_age))
break
elif guess_age > age_of_csicsi:
print("try younger...")
else:
print ("try older!")
count += 1
if count == 3:
continue_confirmation = input("Do you want to keep trying?")
if continue_confirmation != 'n':
count = 0
#else:
# print("You've tried too many times... Bye...")
continue 跳出本次循环进入下次循环 break 结束整个循环
# Author: csicsi
for i in range(10):
print('-----------',i)
for j in range(10):
print(j)
if j > 5:
break
# Author: csicsi
age_of_csicsi = 23
for i in range(3):
guess_age = int(input("guess age of csicsi:"))
if guess_age == age_of_csicsi:
print("You are a genius! csicsi is {age}.".format(age=guess_age))
break
elif guess_age > age_of_suzy:
print("try younger...")
else:
print("try older!")
else:
print("You've tried too many times... Bye...")