Python學習第一天

從網上找了個在線的文檔 http://www.runoob.com/python/python-tutorial.html html

就按照上面的例子學起來了,不過我開始學的是python3.5.1,不知道是否是太新了。python

如下是第一天本身練習的簡單內容,固然是按照文檔寫的例子,不過有的格式會有些不同this



#!/usr/bin/pythonspa

# -*- coding:UTF-8 -*-code

# filename:test.pyhtm

#element

#part onejade

if True:文檔

print ("Answer")get

print ("True")

else:

print ("Answer")

print ("False")

#part 2

print ("hello python"); #the first note


#PART 3

input("\n\nPress the enter key to exit.")


#part 4

import sys; x='foo';sys.stdout.write(x + '\n')

#part 5

counter = 100 #zheng xing

miles = 1000.0 # fudianxing

name = "John" #zifuchuan


print (counter)

print (miles)

print (name)


str = "what\'s hello world"

print (str) 

print (str[0]) #OUTPUT the first character

print (str[2:5]) #output from the third to the fifth

print (str[2:]) # output from the third character

print (str*2) #output the str twice

print (str + 'test') # output the connected str


list=['abcd',786,2.33,'jade',19.3]

tinylist=[124,'jade']


print (list) # output list

print (list[0]) # output the first element

print (list[1:3]) #output from the second to the third

print (list[2:]) #output from the third to the last one

print (tinylist*2) # output twice

print (tinylist+list) #


tuple=('abdc',100,1.1,'jade',13.1)

list=['abcd',100,1.1,'jade',13.1]

#tuple[2]=1000 #this is a wrong grammar

list[2]=1000

 

print (tuple)

print (list)


dict = {}

dict['one'] = "this is one"

dict[2] = "this is two"


tinydict = {'name':'john','code':6734,'dept':'sales'}

print (dict['one'])

print (dict[2])

print (tinydict)

print (tinydict.keys())

print (tinydict.values())

相關文章
相關標籤/搜索