Python基本练习

#encoding=utf-8

importcalendar

importtime

importjxdnumber

foriin"jinxudong":

printi;

name="jinxudong"

printname *3

printname[2]

printname[0]

printname[-1]

printname[0:5]

print"jin"inname

print"zhe"inname

if"xu"inname :

print"jin"+"属于jin"

print8*67

print"你好 '金旭东'"

ifTrue:

print"True"

else:

print"False"

#'''用于多行文本快捷写法

'''

多行注释

'''

print'多行注释'

total='''

hhh

fff

ddd

'''

printtotal

#同一行显示多条数语句用;隔开

print"a";print"b"

#,不换行输出

print"x",

print"y"

sum=8+4

ifsum==11:

print12

elifsum==12:

print12

else:

print"其他"

test="jinxudong"

printtest[2:]

list1=["a","jin","hello","hhh"]

list2=["test","gag"]

#合并两个list

printlist1+list2

map={'a':'hhh','b':'fdfdf'}

printmap['b']

printlist2[1]

printmap.keys()

printmap.values()

print"----------------------------测试数据类型转化--------------------------"

a=3.34

printint(a)#数据类型转化

printstr(a)#转化字符串

#ord 查看ASSI值

printord('A')

print5%2

print5/2

count=0

whilecount<10:

count+=1

printcount

c="c"

d="cd"

printcnot  ind

printcind

test4="aaabbbdfdfggdaafttgdaagdgd"

#str.count('a') 统计a在str中出现的次数

printtest4.count('a')

#在0到5号元素之间出现的次数

printtest4.count('a',0,5)

test6="abc"

printtest6.__len__()

#find找出索引值

printtest6.find('a')

#replace替换

test6=test6.replace("a","ff")

printtest6

now=time.localtime(time.time())

now1=time.asctime(now)

printnow

print"格式化的日期:"+now1

#自定义日期格式化格式

printtime.strftime("%Y-%m-%d %H:%M:%S",now)

#输出日历

printcalendar.month(2017,11)

deffunone (par):

printpar

funone("hello world")

defsum (a,b):

returna*b

printsum(3,5)

#调用自定义模块

printjxdnumber.sumnum(5,8)

jxdnumber.hello()

你可能感兴趣的:(Python基本练习)