Learning with python: Chapter2 Variables, expressions and statements

20个关键词:

and def exec if not return assert del finally import or try  break elif for in pass while class else from is print yield continue except global lambda raise


[root@CentOS python]# python
Python 2.6.6 (r266:84292, Feb 21 2013, 23:54:59)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 4  # use print
4
>>> type("Hello world!")  # use type()
<type 'str'>
>>> type(3.2)
<type 'float'>
>>> print 1,000,000   # use , operator print multi-variables
1 0 0
>>> Message="What's up?"  # string
>>> n=17
>>> pi=3.1415926
>>> print Message   # print string

What's up?
>>> print n
17
>>> print pi
3.1415926
>>> type(Message),type(n),type(pi)
(<type 'str'>, <type 'int'>, <type 'float'>)
>>> 1+1
2
>>> 17
17
>>> Message   # string, compare with "print string"
"What's up?"
>>> 5**2,4*3  # ** is exponent and * is multiply
(25, 12)
>>> minute=59
>>> minute/60   # round off

0

>>> minute*100/60
98
>>> 3*1**3    # ** is prior to *

3
>>> (3*1)**3
27
>>> print Message + "Ted."   # operate string
What's up?Ted.
>>> print Message*3  # print Message for 3 times
What's up?What's up?What's up?

>>> percentage=(minute*100)//60  # // is same as / as a division operator
>>> percentage

98
>>> percentage=(minute*100)/60
>>> percentage

98


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值