python 小白学习之路(内含彩蛋)

python占位符

  1. %s 字符串占位符
  2. %d integer占位符
  3. %f 浮点占位符
版本一:
	username = input("name")
	age = str(input("age"))
	print(type(age))
	job = input("job")
	salary = input("salary")
	
	info = '''
	------ hello world -----
	username = %s username
	age = %d age
	job = %s job
	salary = %s salary
	''' %(username,age,job)
	print(info)
版本二:
username = input("name")
age = input("age")
job = input("job")
salary = input("salary")

info = '''
------ hello world {_name} -----
username ={_name}
age = {_age}
job = {_job}
salary = {salary}
''' .format(_name = username,_age = age,salary=salary,_job=job)
print(info)
版本三:
username = input("name")
age = input("age")
job = input("job")
salary = input("salary")

info = '''
------ hello world {0} -----
username ={0}
age = {1}
job = {2}
salary = {3}
''' .format(username, age,salary,job)
print(info)
python 字符串强转Integer

age = int(str)

pyhton integer 强转 字符串

name = str(age)

pyhton 单行注释
python 多行注释 ‘’’ ‘’’

if else 的使用

示例一:
name = 'lianghengyu';
world = 123456;
username = input("name")
passworld =int(input("passworld"))

if name == username and world == passworld:
    print("wellcome my live")
else:
    print("invalue passworld or username")
实例二:
age = 28

guess_age =int(input("guess age:"))

if age == guess_age:
    print("you are right")
elif age < guess_age:
    print("think smaller...")
else:
    print("think bigger....")
注意事项:

1 passworld 的转码,转成int 类型
2 if 和 else 的条件后面跟 : 冒号

while 循环的使用 break退出

age = 28
count = 1
guess_age =int(input("guess age: "))

while age != guess_age:
    if count>2:
        print("you have not chance")
        break;
    if age < guess_age:
        print("think smaller....")
    else:
        print("think bigger....")
    guess_age = int(input("guess age: "))
    count+=1
else:
    print("you are right")

for 循环

num = 10
for i in range(3):
    you_num =int(input("guess you num:"))
    if you_num == num:
        print("you are right")
        break
    elif you_num>num:
        print("think smaller")
    else:
        print("think bigger")
if num != you_num:
    print("you are not chance")

python 零基础学习
下载链接:https://pan.baidu.com/s/1YlEXYGhMAcDKX2rLXoOsNQ 密码:3xmj
如果感兴趣,可以联系作者要后续资源
或加微信好友,共同探讨学习,共同进步(备注:python 探讨)
VX号:lhy83568725566

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值