标签:
1、python介绍
2、python程序初接触和变量
3、python用户交互
4、python数据类型
5、python循环if...(elif)...else
6、python循环while...else
7、python循环for...else
8、python循环中断break和continue
先看优点:
再看缺点:
print (“Hello,world!”)#第一个python程序
b=2
c=3
print (b,c) #变量赋值
b=22
print (b,c) #变量指向内存地址
name="spider"
print (name) #变量赋值(字符串)
蜘蛛 = "spider" #python2与python3区别
print (蜘蛛)
python2中input即为python3中的input(用法一致)
python2中的raw_input,输入什么类型就输出什么类型;python3中没有raw_input
name = input(‘Name:‘)
age = input(‘Age:‘)
print (type(age))
job = input(‘Job:‘)
salary = input(‘Salary:‘)
info3=‘‘‘
-----information of info3 {0}
Name:{0}
Age:{1}
Job:{2}
Salary={3}
‘‘‘.format(name,age,job,salary)
print (info3)
info2=‘‘‘
------information of info2 {_name}------
Name:{_name}
Age :{_age}
Job :{_job}
salary:{_salary}
‘‘‘ .format(_name=name,
_age=age,
_job=job,
_salary=salary)
print (info2)
info1 = ‘‘‘
-------information of info1 %s-------
Name:%s
Age :%s
Job :%s
Salary :%s
‘‘‘ %(name,name,age,job,salary)
print (info1)
info=‘‘‘
---------information of info ‘‘‘ + name +‘‘‘--------
Name:‘‘‘ + name + ‘‘‘
Age :‘‘‘ + age + ‘‘‘
Job :‘‘‘ + job + ‘‘‘
Salary :‘‘‘ + salary
print (info)
数字int 浮点f 字符串s bool:Ture和False
ASCII :American Standard Code for Information Interchange ,美国标准信息交换代码 占1byte
GB2312:1980年诞生,支持7000个中文,占2bytes
GBK:1995年诞生,支持2万个中文,占2bytes
GB18030:2000年诞生,支持蒙、藏、维等字符,支持2.7万文字,占2bytes
注:以上均向下兼容;
后来unicode诞生,又叫万国码、统一码,支持以上格式,兼容他国语言,占2bytes
由于资源浪费,UTF-8诞生,可变长度的unicode,ASCII中的内容占1byte,欧洲的字符占2bytes,东亚的字符占3bytes(赤裸裸的剥削)
#密文密码输入 getpass模块 pycharm下无法实现,在linux系统下可以实现
import getpass
‘‘‘ #输入用户名和密码正确欢迎,错误返回错误消息
_username = ‘spider‘
_password = ‘123‘
username = input("请输入用户名:")
#password = getpass.getpass("请输入密码:") #密文输入
password= input("请输入密码:")
if username == _username and password == _password:
print ("Welcome user {a} login...".format(a=username))
else:
print ("invalid username or password")
print (username,password)
‘‘‘
Age_of_oldboy = 78 #猜数字,对了打印信息,最多猜三次,都错误返回信息
count = 0
while count<3:
guess_age = int(input ("gusee oldboy‘s age:"))
if guess_age == Age_of_oldboy:
print ("Yes,you got it!")
break
elif guess_age > Age_of_oldboy:
print ("You are wrong,guess smaller...")
else:
print ("You are wrong,guess bigger!")
count +=1
else:
print ("you have tried too many times.. Please go out!")
Age_of_oldboy = 78 #猜数字,对了打印信息,最多猜三次,都错误返回信息
for count in range (3):
guess_age = int(input ("gusee oldboy‘s age:"))
if guess_age == Age_of_oldboy:
print ("Yes,you got it!")
break
elif guess_age > Age_of_oldboy:
print ("You are wrong,guess smaller...")
else:
print ("You are wrong,guess bigger!")
举例1:
for i in range(0,10): #i<5则继续向下执行,打印j,i>5则不向下执行,不打印j
print ("---------",i)
if i> 5 :
continue
for j in range(0,10):#j<5则打印j,j>5则跳出该循环
print (j)
if j > 5:
break
举例2:
for i in range(0,10): #当i>5,跳出循环,不向下执行,当i<5,向下执行
print ("---------",i)
if i> 5 :
break
for j in range(0,10):
print (j)
if j > 5:
continue
标签:
原文地址:http://www.cnblogs.com/sunfu/p/5821938.html