pythonfor循环输入_python入门(输入、输出、if else 判断流、while循环、for循环)...

# -*- coding:utf-8 -*- ———————— 申明字符编码集

注释:当行 —#

多行 — “”” “”” 或者 ‘’’ ‘’’ (在python中单引号双引号没有区别)

1、 输出

print ("hello word !")

2、 变量

定义编码:name = "hui"

使用编码:print ("name is",name) (变量之间逗号隔开)

打印变量数据类型:print(type(name))

3、 用户输入

输入格式:username

= input(“username:”)

转换输入数据类型:age=int(

input(“password:”) )

加密显示输入:

import getpass

#引用密码包

password =

getpass.getpass("password:")

4、格式化输出

列:name = input("name:")

age = input("age:")

sex = input("sex:")

height = input("height:")

# 方式1:(字符串拼接用 +)--建议不使用

msg = ‘‘‘------- msg of ‘‘‘ + name + ‘‘‘ -------

name:‘‘‘ + name +‘‘‘

age:‘‘‘ + age + ‘‘‘

sex:‘‘‘ + sex + ‘‘‘

height:‘‘‘ + height

print (msg)

方式2:占位符 %s

(s——string简写)--不推荐

msg = ‘‘‘------- msg of %s -------

name:%s

age:%s

sex:%s

height:%s

‘‘‘%(name,name,age,sex,height)

print (msg)

方式3:--不推荐

msg = ‘‘‘------- msg of {0} -------

name:{0}

age:{1}

sex:{2}

height:{3}

‘‘‘.format(name,age,sex,height)

print (msg)

方式4:推荐使用

msg = ‘‘‘------- msg of {name_1} -------

name:{name_1}

age:{age_1}

sex:{sex_1}

height:{height_1}

‘‘‘.format(name_1=name,

age_1=age,

sex_1=sex,

height_1=height)

print (msg)

4、 if else 流程判 username_a = ‘qaz‘

password_a = ‘123‘

username = input("username:")

password = input("password:")

if username == username_a and password == password_a:

print("Welcome user {name} login...".format(name=username))

else:

print("Invalid username or password!")

5、 while 循环

username_a= ‘qaz‘password_a = ‘123‘entry_count=0

whileentry_count<3:

username = input("username:")

password = input("password:")

ifusername

== username_a andpassword == password_a:

print("Welcome user {name} login...".format(name=username))

break

else:

print("Invalid username or password! Please Try

Again")

entry_count +=1

else:

print("you have tried too many times..fuck

off")

6、 for 循环

fori inrange (0,10,1):

print(‘----------‘, i)

forj inrange(10):

ifj >

5:

break

else:

print(j)

原文地址:https://www.cnblogs.com/56321pia/p/10129776.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值