开始学习python,day1
一丶 Python变量
变量定义的规则:
- 变量名只能是 字母、数字或下划线的任意组合
- 变量名的第一个字符不能是数字
- 以下关键字不能声明为变量名
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
二丶 注释
当行注视:# 被注释内容
多行注释:""" 被注释内容 """
三丶 用户输入
name = input("What is your name?")
print("Hello " + name )
输入密码时,如果想要不可见,需要利用getpass 模块中的 getpass方法,即:
import getpass
pwd = getpass.getpass("请输入密码:")
print(pwd)
四丶模块
Python的强大之处在于他有非常丰富和强大的标准库和第三方库,几乎你想实现的任何功能都有相应的Python库支持,以后的课程中会深入讲解常用到的各种库,现在,我们先来象征性的学2个简单的。
import sys
print(sys.argv)
$ python test.py helo world['test.py', 'helo', 'world'] #把执行脚本时传递的参数获取到了五丶数据类型
与c#差不多 #bf571a
六丶字符串拼接
python中的字符串在C语言中体现为是一个字符数组,每次创建字符串时候需要在内存中开辟一块连续的空,并且一旦需要修改字符串的话,就需要再次开辟空间,万恶的+号每出现一次就会在内从中重新开辟一块空间。
name = "zhouquan"
print "i am %s " % name
username = input("username:")
pwd = input("pwd:")
age = int(input("age:"))
print(type(age))
msg = '''
name:%s
pwd:%s
age:%d
''' % (username,pwd,age)
msg2 = '''
name:{0}
pwd:{1}
age:{2}
'''.format(username,pwd,age)
七丶while循环 for循环,break,continue
和c#差不多

浙公网安备 33010602011771号