print'hello world'
print'hello world'
print'hello world'
print'hello world'
print'hello world'
print ('hello world')
print 123
print 123
A = 'hello python world'
a = 'hello python'
a = 'hello 123456' #赋值a被重新定义#
print A
print a
python3中有六个标准的数据类型:
number(数字)
string(字符串)
list(列表)
tuple(元组)
sets(集合)
dictionary(字典)
var1 = 1
var2 = 10
print type(var1)
var3 = 3.14
print type(var3)
var4 = "my name is CGJ"
print type(var4)
类型int、long、float、complex(python3支持int、float、bool、complex)
字符串大小写
name = "i love you"
print name
print (name.title()) #首字符大写
print (name.upper()) #转换为大写
print (name.lower()) #转换为大写
合并字符串
first_name = 'chen'
last_name = 'guanjin'
full_name = first_name+' '+last_name
print full_name
list = ['abcd',123,456,'xuegod',3.14]
print list
print list[0]
print list[1:3] #输出第二个和第三个
print list[2:] #输出第三个及后面全部
tinylist = [123,'xuegod']
print tinylist*2 #打印两遍
print list+tinylist
list[0]=1234 #重定义列表list第一个值
print list #list内置方法,如append()、pop()等
小括号,元组内元素无法单独自定义
tuple = ('abcd',123,456,'xuegod',3.14)
tinytuple =(123,'xuegod')
print tuple
print tuple[0]
print tuple[1:3]
print tuple[2:]
print tinytuple*2
print tuple+tinytuple
Set集合:
一个无序不重复元素的序列;
基本功能是尘缘关系测试和删除重复元素;
注意1:空集合用set{},非{},因{}用来创建空字典
student= {'mk','top','tree','cd','while','for','mk'}
print student
a = set('123456')
b = set('456789')
print a-b #a和b的差集
print a&b #a和b的交集
print a|b #a和b的并集
print a^b #a和b中不同时存在的元素
dict = {}
dict['one'] = '1-xuegod'
dict['two'] = '2-xuegod'
tinydict = {'name':'xuegod','site':'xuegodIT.com'}
print dict['one']
print dict['two']
print dict
print tinydict
print dict.keys()
print dict.values()