python基础语法,字符编码,python解释器在加载 .py 文件中的代码时,会对内容进行编码(默认ascill)

print("Hello word")

一个简单hello word输出

name = “kevm”

name2 = name

print ("my name is ",name,name2)

简单的一个变量输出,在开发程序里,没有标准的输入,但是必须有标准的输出,

多行注释,标准格式化输出放有三种,分别如下

name = input( "name :")                #输入
age = int(input("age:"))             #输入 #强制把字符串转换成整数 print(type(age) , type ( str (age) ))      #强制整形转换字符串 #type( str (age))                  #转换成正兴
job = input("job: ")                 #输入 info = '''
=================info of %s ===============
Name:%s
Age:%d
Job:%s
''' % (name,name,age,job)
print(info) '''第一种格式化输出'''
#定义模块输出
#%s整数检测
#%d帮助检查数据类型
#%f 检测浮点 #格式化输出
'''
%% 百分号标记 #就是输出一个%
%c 字符及其ASCII码
%s 字符串
%d 有符号整数(十进制)
%u 无符号整数(十进制)
%o 无符号整数(八进制)
%x 无符号整数(十六进制)
%X 无符号整数(十六进制大写字符)
%e 浮点数字(科学计数法)
%E 浮点数字(科学计数法,用E代替e)
%f 浮点数字(用小数点符号)
%g 浮点数字(根据值的大小采用%e或%f)
%G 浮点数字(类似于%g)
%p 指针(用十六进制打印值的内存地址)
%n 存储输出字符的数量放进参数列表的下一个变量中
'''
info2 = '''
=================info of {_name} ===============
Name:{_name}
Age:{_age}
Job:{_job}
''' .format ( _name=name,
_age=age,
_job=job )
print(info2) '''第二种格式化输出''' info3 = '''
================info of {0}===============
Name:{0}
Age:{1}
Job:{2}
''' .format(name,age,job)
print(info3)
'''第三种格式化输出'''

输出结果如下

================================================================================

D:\Python35\python.exe D:/项目开发/pady01/pady01/name_user.py
name :ke
age:34
<class 'int'> <class 'str'>
job: sdfw

=================info of ke ===============    #第一种格式化输出

Name:ke
Age:34
Job:sdfw

=================info of ke =============== #第二种格式化输出
Name:ke
Age:34
Job:sdfw

================info of ke===============    #第三种格式化输出
Name:ke
Age:34
Job:sdfw

*//常用的是最上面两个格式化输出,第三种格式化输出比建议使用//*

name = input("username:")       #输入
#password = getpass.getpass("password:")  #这个模式在python的GUI才能实现输入  
password = input("password:")      #这个password在pytharm开发工具里可以使用
print( name,password) #标准的答应输出
========================================================
import  getpass
_username = 'kevm'
_password = '123456'
username = input("username: ")
#password = getpass.getpass("Password: ")
password = input("Password: ")
#password = input("Password:") #if _username == username and _password == password:
# print("Welcome user {name} login...".format(name=username))
#else:
# print("Invalid username Password") if _username == username and _password == password:
print("Welcome user {name} login ...".format(name=username))
else:
print("Invalid username or password",password)
一个简单的用户登录时,输错密码三次,提示账户被锁定,要求找管理解锁
while循环
count = 0                   #count 等于0 
while True:          #在while条件成为真的情况下,会不停一直循环,
print("count:",count) #打印输出没循环一次的count值
count = count +1 #count +=1 #每次加一
if count == 1000: #等到count值是1000的时候,就会停止无限循环
break            #break 是终止循环,
=========================================================================================
age_of_oldboy = 56           #

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

while True:                              #while循环,规定次数
if conut ==3:
break
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy:
print("yes, you got it.")
break
elif guess_age > age_of_oldboy:
print("think smailer....")
else:
print("think bigger!...")
conut +=1 for i in range(3):                                 #for循环规定制定次数循环
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy:
print("yes, you got it.")
break
elif guess_age > age_of_oldboy:
print("think smailer....")
else:
print("think bigger!...")
#正常走完上面的代码才会执行下面代码
else:
print("you have tried tooo many times .. fuck off")
===================================================================================================
任性猜年龄
age_of_oldboy = 56
count = 0
while count <3:
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy:
print("yes, you got it.")
break
elif guess_age > age_of_oldboy:
print("think smailer....")
else:
print("think bigger!...")
count +=1
if count == 3:                                          #添加了一个if判断,你是需要继续玩下去,如果要玩下去,回车键,不先想玩下去,选择输入n结束
countine_confirm = input("do you want to keep guessing ...?")
if countine_confirm !='n':
count =0
else:                                                 #有了if判断,eles就不需要了
print("you have tried tooo many times .. fuck off")
===========================================================================================================================================================================================
for i in range(0,10,2):
print("loop ",i)
#输出双数,跳一个打印输出一个,python里默认是1,
=========================================================================================================================================================================================
for i in range(0,10):                                       #打印输出三次,停止for循环输出
if i <3:
print( "loop ", i)
else:
continue                                        #continue是继续
print("hehe!!")
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
for i in range(10):                                    #for循环中for,可以添加多个for循环,
print('...............',i)
for j in range(10):                                  
print(j)
if j >5:                                      #if判断5大于就会停止for循环,
break                                      #结束当前的for,bareak
05-08 08:34