python(2)

    1.第一个“hello world”程序

print("hello world")   #输出hello world
exit()     

    需要注意的一点是python语句的末尾不需要加分号的


    2.变量名的定义规则:

    变量名只能是字母、数字、下划线的任意组合;变量名的的第一个字符不能是数字;关键字不能声明为变量。


    3.python中没有常量的定义,一般用大写字母为我们自己所定义的常量赋值:

PIE = 3.1415926

    

    4.ASCII码(1字符=1字节)

    Unicode编码(1字符=1字节)

    UTF-8编码(英文1字符=1字节,中文1字符=3字节)


    5.单行注释:#hahahaha

    多行注释:'''hahhahhah'''


    6.输入函数input

name =input("你的名字:")


    7.输出方式:

    (1)字符串拼接方式

name = input('你的名字:')
print(name+"你真好")

    (2)用占位符的方式

name=input("你的名字:")
age=input("你的年龄:")
print("%s 果然是一个 %d 的少年呀!"%(name,int(age)))

    (3)用format函数

name=input("你的名字:")
age=int(input("你的年龄:"))
sex=input("你的性别:")
info1="{Name}是一个{Age}岁的{Sex}人".format(Name=name,Age=age,Sex=sex)
info2="{1}是一个{0}岁的{2}人".format(age,name,sex)
print(info1)
print(info2)


    8.密文输入getpass

    在pycharm平台中不好使。

import getpass
username = input("username:")
password =getpass.getpass("password:")
print(username,password)
原文地址:https://www.cnblogs.com/wangchongzhangdan/p/9409639.html