Python第一阶段01
1.变量:
name = "sisi" print(name) age = 11 print(age)
2.常量:
PIE = 3.1415926
3.注释:
# password = "aaaa" '''password = sisi'''
"""aaaaaaaaaa
aaaaaaa"""
4. 输出多行字符:
a = '''haha efefejfijeofjeof djendejndenfef ''' print(a) b = """aaaaaaaaaa aaaaaaa""" print(b)
5.用户交互程序:
name = input("name:") age = input("age:") salary = input("salary:") print(name, age, salary) print(type(age)) a = '''name = %s, age = %s, salary = %s''' % (name, age, salary) b = '''name = {name}, age = {age}, salary = {salary}''' c = '''name = {_name}, age = {_age}, salary = {_salary}'''.format(__name = name, __age = age, __salary = salary) d = '''name = {0}, age = {1}, salary = {3}''' print(a)
6.密码密文输入:
import getpass username = input("name: ") password = getpass.getpass("password: ") print(username, password)
7. if...else流程判断:
import getpass name = "sisi" passwd = "123" username = input("name: ") # password = getpass.getpass("password: ") password = input("password: ") if username == name and password == passwd: print("Loggin in...")
print("Welcome user {name} login...".format(name = username))
print(username, password)
else: print("error")
8.While循环:
count = 0 while True: print("count: ", count) count = count + 1 if count == 100: break
9.循环优化for循环:
for i in range(10): print("loop", i ) #0 ~10 for i in range(0, 10, 2): # range(开始值,结束值,步长) print(i)