python 入门 《第一篇》

# 变量分为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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值