rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » Python

python3学习1

不学习怎么行呢。。。python还是相当好学习得语言,没有编程基础的我也能跟下去。1. 安装,因为mac os,已经自带2.5,不过3.2变化很大,还是从官网上下载了3.2;
安装完后有自带工具将python3路径写到$PATH, /Library/Frameworks/Python.framework/Versions/3.2/bin
2. 运行:
$python3.2 or 3    #goes to version 3.2 or 3.x
$python2              #goes to version 2.x
3. 与2.x的区别:
因为看得是2.x的学习文当,发现许多例子3.2跑不通,目前看最显著的就是print,在3.x里面是function而不是keyword argument, 这里有详细的说明。
4.the basics:
a. numbers and expressions
@numbers: integers, large integers(long)
@expressions: + - * %
@hexdecimals and octals
b. variables
>>>x=3
>>>x*2
c. statement
$if 1==2, print ("false")
d. user input
>>>input ("the meaning of life is: ")
>>> x = input("x: ")
x: 34
>>> y = input("y: ")
y: 42
>>> print x * y
1428
e. functions: pow(), print(), round()
f. modules: import4. try out script:
a. hello.py
#!/Library/Frameworks/Python.framework/Versions/3.2/bin/python3
name=input("What's  your name: ")
print ("Hello "+ name +"!")
b. chmod 755 hello.py
c. python3 hello.py OR ./hello.py5. comments starts with #
6. strings, quotes(single, double, escaping),字符串连接。。。
Let's go >>>> "Let's go" or 'Let\'s go'
"hello world" = print ("hello world")Functions Summary:Note: raw_input not working on python 3.
顶一下
(0)
踩一下
(0)