[python]学习笔记1

查看python版本
C:\>python -V
Python 2.7.5

退出python
exit()
ctrl+Z

第一个程序
>>> print 'hello world'
hello world
>>> print "hello world"
hello world
>>> print ('hello,world')
hello,world

变量
>>> a=1
>>> a
1
>>> a=23456786
>>> a
23456786
>>> a=1.87543368
>>> a
1.87543368
>>> a=1i+2j
  File "<stdin>", line 1
    a=1i+2j
       ^
SyntaxError: invalid syntax
>>> a=1+2j
>>> a
(1+2j)
>>> _a=2
>>> _a
2
>>> _A
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_A' is not defined
#python中要区分大小写

>>> username='cindy'
>>> username
'cindy'
>>> pi=3.14
>>> pi
3.14
>>> print

>>> print pi
3.14

查看数据类型
>>> a=3.14
>>> type(a)
<type 'float'>
>>> a='abc'
>>> type(a)
<type 'str'>
>>> a=abc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'abc' is not defined
>>> a=0
>>> type(a)
<type 'int'>
>>> a=True
>>> type(a)
<type 'bool'>


换行输出数据,用三个引号
>>> a="""1
... 2
... 3
... 0
... """
>>> print a
1
2
3
0
>>> a
'1\n2\n3\n0\n'
>>>
>>>
换行输出数据,用\n
>>> a='1\n2'
>>> a
'1\n2'
>>> print a
1
2

求加、减、乘、除、幂
>>> num1=3.14
>>> num2=5
>>> print num1+num2
8.14
>>> print num1-num2
-1.86
>>> print num1*num2
15.7
>>> print num1/num2
0.628
>>> print num1**num2
305.244776182
>>>

求除、余
>>> num1=89
>>> num2=10
>>> print num1/num2
8
>>> print num1%num2
9

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值