python占位符
- %s 字符串占位符
- %d integer占位符
- %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