Step by Step Learn Python(1)

 

print "Hello World!"

action = raw_input("please select your action{1, 2, 3, 4, 5, 6, 7, 8, 9, o}: ")
print action

if action == str("1"):  #print hello name
	name = raw_input("what's your name?  ")
	print "Hello "+name
elif action == str("2"): #print hu and chongshi
	hu =["hu", 25]
	chongshi=["chongshi", 32]
	database = [hu, chongshi]
	print database
elif action == "3":
	greeting = "chongshi" #print c
	print greeting[0]
elif action == "4":
	fourth = raw_input("year:")[3] #year:2013 print 3
	print fourth
elif action == "5":
	tag = '<a href="http://www.python.org">Python web site</a>'
	print tag[9:30]
	print tag[32:-4]
elif action == "6":
	permissions = "rw"
	print "w" in permissions
	
	users = ["hls", "lisi"]
	r = raw_input("enter you user name:") in users #return true or false check input value is not at users
	print r
elif action == "7":
	numbers = [100, 34, 678]
	print "max(numbers) "+ str(max(numbers)) #get max value for numbers

	print "min(numbers) "+ str(min(numbers)) #get min value for numbers
elif action == "8":
	lis = list('chongshi')

	x = [1,3,4]
	x[1] = 2
	print x  #update item value

	del x[1]  #delete a item
	print x

	x[1:] = list("111v123") #append a list at index 1 of x
	print x

	print 'there have '+str(x.count("1"))+' "1"' #get contains "1" of list x's value

	y = [4,5,6,7,8]
	x.extend(y) #extend y to x
	print x


	print x.index("1") #get index for "1"

	x.insert(5, "5.5") #insert a value at index 5 later
	print x

	x.pop() #delete a last item
	print x

	x.pop(1) #delete index 1's value
	print x 

	x.remove() #delete a first item
	print x

	x.reverse() #reverse items
	print x

	x.sort()
	print x
elif action == "9": #tuple
	z = 1,2,3
	print z

	z = tuple("12346abc")
	print z

else:
	print '''this is a  very long string.
		It continues here.
		and it's not over yet.'''

 

posted @ 2015-11-14 23:49  iDEAAM  阅读(261)  评论(0编辑  收藏  举报