安装pycharm
cd ~/downloads
tar -zxvf pycharm-community-2020.1.3.tar.gz
mv pycharm-community-2020.1.3 /opt/
sudo mv pycharm-community-2020.1.3 /opt/
/opt/pycharm-community-2020.1.3/bin/pycharm.sh
界面化着步安装
sudo apt-get install python3-distutils
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
sudo apt install launchpadlib
正常创建Projiect
1变量
代码:
name = "town"
name2 = name
print ("my name is ", name2)
name = "lili"
print ("my name is ", name, name2)
#a变量指向b变量时。是直接指向b变量的值,后面改变b变量的值是不会改变其a变量的值。
ASCLL类字符编码
百度连接:https://baike.baidu.com/item/字符编码/8446880?fr=aladdin
#_*_ coding: utf-8 _*_
#Author:TOWN
print ("中国你好") # python3 自带中文 python须注释编码
简单登陆判断(if)
import getpass # 引用脚本
_username = "town"
_passwd = "town"
username = input("name:")
passwd = getpass.getpass("passwd:") # 隐藏输入
print(username,passwd)
if _username == username and _passwd == passwd:
print("Welcome user {name} login...".format(name=username))
else:
print("Invalid username and password!"
#后续更新登陆接口程序。三次登陆锁定 采用python内部调用文件接口命令;两个文件:1.账号密码文件2锁定文件
格式化输出
name = input("name:")
age = int(input("age:")) # 默认是字符串 int(input())整数
print(type(age)) # 打印变量类型
job = input("job:")
salary = input("salary:")
print(name, age, job, salary)
info = '''
--------info of %s-----------
name:%s
age:%s
job:%s
salary:%s
''' % (name, name, age, job, salary) # %d 整数 %f浮点 %s 字符串
print(info)
info2 = '''
----------info2 of {a}-------------
name:{a}
age:{b}
job:{c}
salary:{d}
''' .format(a=name,
b=age,
c=job,
d=salary)
print(info2)
info3 = '''
----------info3 of {0}-------------
name:{0}
age:{1}
job:{2}
salary:{3}
''' .format(name,
age,
job,
salary) # 开辟多个内存空间 运行慢 不建议使用
print(info3)
while和for循环 及计数(猜年龄)
age_of_town = "29"
count = 0
'''while True:
if count ==3:
print("you have tried too many times..fuck off")
break
guess_age = input("gess age:")
if guess_age == age_of_town:
print("yes,you got it")
break
elif guess_age > age_of_town:
print("think smaller")
elif guess_age < age_of_town:
print("think biger")
count +=1'''
'''
while count<3:
guess_age = input("gess age:")
if guess_age == age_of_town:
print("yes,you got it")
break
elif guess_age > age_of_town:
print("think smaller")
elif guess_age < age_of_town:
print("think biger")
count +=1
else:
print("you have tried too many times..fuck off")
'''
for i in range(3):
guess_age = input("gess age:")
if guess_age == age_of_town:
print("yes,you got it")
break
elif guess_age > age_of_town:
print("think smaller")
elif guess_age < age_of_town:
print("think biger")
else:
print("you have tried too many times..fuck off")
任性玩猜年龄
age_of_town = 29
count = 0
while count < 3:
guess_age = int (input("gusee age:"))
if guess_age == age_of_town:
print("you got it")
break
elif guess_age > age_of_town:
print("gusee age is biger")
else:
print("guess age is smaller")
count +=1 # 这里会忘记 然后会一直循环
if count == 3:
valus = input("input y to continu:")
if valus == "y":
count=0
else:
print("you have trying many times...fuck off!!!")
嵌套循环
'''
for i in range (0, 10):
if i < 3:
print("loop", i)
else:
continue # continue 结束本次循环 继续下次循环;break 结束循环
print("hehe...")
'''
for i in range(1,10):
print("---------",i)
for j in range(1,10):
print(j)