Python学习笔记

2017-03-28  本文已影响0人  流弊的小白

[Toc]

1注释

单行注释#
print('你好')
# 我是注释
多行注释
print('你好')
'''
我是注释
'''
#encoding=utf-8
例如:print('你好')
urf-8是一种编码方式

2变量以及类型

1变量类型

  1. Numbers(数字)
  1. 布尔类型
  1. String(字符串)
  2. List(列表)
  3. Tuple (元组)
  4. Dictionary (字典)

带上小数点是浮点型float 不带小数点是整形int
定义变量同时给他一个值 叫初始化
第二个叫赋值 不叫初始化

不允许变得叫常量
可以改的叫变量
例:
a=100
a是变量
100是

4标识符和关键字(模块的调用方法)

>>> import keyword   
#导入keyword
>>> keyword.kwlist
#从keyword查看kwlist
['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']
>>>
>>> from keyword import kwlist 
#从keyword模块导入kwlist 
>>> kwlist
#查看kwlist
['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']
>>>

5输出

1.普通的输出

print(hello word)

2.格式化输出

格式化操作目的

>>> score=100
>>> score
100
>>> print("score")
score
>>> print("my enlish sore is %d" %score)
#在括号内写%d,然后在外面写上需要打印的值在值前面加上%即可;(输出时会把%d替换成score,这种方法叫格式化输出)
my enlish sore is 100
>>>
 score=100
 mathScore=95
print("my enlish sore is %d" %score)
my enlish sore is 100
print("enligh score is %d,,,,,,math score is%d"%(score,mathScore))
enligh score is 100,,,,,,math score is95

3 换行输出

>>> print("enligh score is %d\nmath score is%d"%(score,mathScore))
enligh score is 100
math score is95

4 练习

name="yy"qq="12345"shouji="18888888888"dizhi="北京"print "姓名"+nameprint"QQ"+qqprint "手机"+shoujiprint "地址"+dizhi
#encoding: utf-8#1.提示用户输入信息name = raw_input("请输入姓名:")qq = input("请输入QQ:")tel = input("请输入手机号码:")#2.从相应的变量中取出数据,然后进行打印print("====================================")print("姓名:%s"%name)print("QQ%s"%qq)print("Tel:%s"%tel)print("=====================================")
#encoding: utf-8
import time
#1.提示用户输入信息
name = raw_input("请输入姓名:")
qq = input("请输入QQ:")
tel = input("请输入手机号码:")
#模拟打印,使用time模块延迟
print("系统正在打印中...3")
time.sleep(1)
print("系统正在打印中...2")
time.sleep(1)
print("系统正在打印中...1")
time.sleep(1)
#2.从相应的变量中取出数据,然后进行打印
print("====================================")
print("姓名:%s"%name)
print("QQ%s"%qq)
print("Tel:%s"%tel)
print("=====================================")从keyword查看kwlist

6#输入
raw_input()

#encoding: utf-8passwod=0passwod= input("请输入密码")print("你的密码是:%d"%passwod)

6运算符

print("="*30)
#带双引号叫字符串
查看字符串类型
a=100
type(a)

赋值运算符

上一篇 下一篇

猜你喜欢

热点阅读