# 變量分爲2種
# 單行註釋
"""多行註釋"""
# 存一箇中文 需要3個字節
# ASCII 只能255 1bytes --> 1980 gb2312 只支持7000多個文字 --> 1995 GBK1.0 支持2w+
# --> 2000 GB18030 27000 --> unicode 2bytes --> utf-8 en:1bytes zh:3bytes
# 定義常量通常使用 大寫
PIE =12;
gf_of_oldboy = "";
GFOfOldboy = "";
print(2**8);
註釋學習
name = "你好, 世界";
msg = '''
打印多行
打印多行
打印多行
''';
print(msg);
input 用戶交互學習:
# username = input("what is name: ");
#
# print("name :"+ username);
# 字符串的組裝 %s 字符串 %d 只接受數字 %f 浮點(小數)
name = input("name:");
age = int(input("age:")); # 轉化類型 將 string 轉爲 integer
# print(type(str(age)));
#
info = '''
--- info of %s -------
name: %s
age: %d
'''%(name, name, age)
# print(info);
# ---------------------------使用這種字符串拼接-------------------
info2 = '''
--- info of {_name} -------
name: {_name}
age: {_age}
'''.format(_name=name,
_age=age);
# print(info2);
# --------------------------------------------------------------------
info3 = '''
--- info of {0} -------
name: {0}
age: {1}
'''.format(name,age);
print(info3);
if else 學習
# 引入模塊(標準庫,只要import)
import getpass
_username = 'alex';
_password = '123';
username = input("username:")
password = input("password:")
# password = getpass.getpass("password:")
# print(username, password)
# 流程控制,邏輯運算()
if _username == username and _password == password:
# 下面這段是上面這段子代碼
print("Welcome user {name} login..".format(name=username))
else:
# 下面這段是上面這段子代碼
print("Invalid username or password !")
# print('ddd');
print('ddd');
# ##################### IndentationError(縮進錯誤)
# print('ddd'); 必須頂格寫,不能留有空隙,否則報縮進錯誤
while 循環:
# 猜年齡 (循環)
'''
age_of_boy = 56
count =0
while count <3:
guess_age = int(input("guess age:"))
if guess_age == age_of_boy:
print("yes, you got it.")
break;
elif guess_age > age_of_boy:
print("think smaller..")
else:
print("think bigger!")
count += 1
else:
print("you have tried too many times .. fuck off")
'''
# while 循環 優化版本
# for i in range(10):
# print("loop:" ,i)
'''
age_of_boy=56
count = 0
for i in range(3):
guess_age = int(input("guess age:"))
if guess_age == age_of_boy:
print("yes, you got it.")
break;
elif guess_age > age_of_boy:
print("think smaller..")
else:
print("think bigger!")
else:
print("you have tried too many times .. fuck off")
'''
# 跳着打印 3 格2個跳一次(補償)默認爲1
# for i in range(0,10,3):
# print("loop:" ,i)
# break 跳出循環 continue
'''
for i in range(0,10):
if i < 3:
print("loop:", i)
else:
continue # 跳出 本次循環,進入下次循環
print("------呵呵呵呵------")
'''
for i in range(10):
print("-------------", i)
for j in range(10):
print(j)
if j >5:
break