设为首页 收藏本站
查看: 568|回复: 0

[经验分享] Python学习入门笔记-基础知识

[复制链接]

尚未签到

发表于 2018-8-11 11:44:09 | 显示全部楼层 |阅读模式
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32  
Type "copyright", "credits" or "license()" for more information.
  
>>> 2 ** 3
  
8
  
>>> -3 **2
  
-9
  
>>> (-3) ** 2
  
9
  
>>> 1111111111111111111111111111111111111111111111111111111111111
  
1111111111111111111111111111111111111111111111111111111111111L
  
>>> 11111111111111111111111111111111111111l
  
11111111111111111111111111111111111111L
  
>>> 2324324523423432432432432L * 2132132143432423423432L
  
4955767028159349056163576467822347272465546624L
  
>>> 0X86
  
134
  
>>> 01010101010101010101
  
18300341342965825L
  
>>> x = 5
  
>>> x % 4
  
1
  
>>> x *9
  
45
  
>>> x+1
  
6
  
>>> y= x+1
  
>>> y
  
6
  
>>> print x+y
  
11
  
>>> z =x +y
  
>>> z
  
11
  
>>> input("the meaning of life: ")
  
the meaning of life: 34
  
34
  
>>> x = input("x: ")
  
x: 9
  
>>> y =input("y: ")
  
y: -9
  
>>> print x+y
  
0
  
>>> if 1 == 2:print 'One equals two '
  
>>> if 1 == 2: print 'One equals two '
  
>>>
  
>>> if 1 ==1 : print 'One equals one '
  
One equals one
  
>>> if time % 60 == 0: print 'On the hour '
  
Traceback (most recent call last):
  
File "<pyshell#29>", line 1, in <module>
  
if time % 60 == 0: print 'On the hour '
  
NameError: name 'time' is not defined
  
>>> pow(2.9)
  
Traceback (most recent call last):
  
File "<pyshell#30>", line 1, in <module>
  
pow(2.9)
  
TypeError: pow expected at least 2 arguments, got 1
  
>>> pow(2 9)
  
SyntaxError: invalid syntax
  
>>> pow(2,9)
  
512
  
>>> pow(2, 2+1)
  
8
  
>>> x= input(" 你想要的数字:“)
  

  
SyntaxError: EOL while scanning string literal
  
>>> x= input(" 你想要的数字:")
  

  
SyntaxError: invalid syntax
  
>>> x = input(" 你想要的数字: ")
  

  
SyntaxError: invalid syntax
  
>>> x= input(" 123:")
  

  
SyntaxError: invalid syntax
  
>>> x = input(" 你想要的数字: ")
  
你想要的数字: pow (2,10)
  
>>> x
  
1024
  
>>> abs(-1)
  
1
  
>>> 1/2
  
0
  
>>> round(1.0/2.0)
  
1.0
  
>>> floor (1,2)
  
Traceback (most recent call last):
  
File "<pyshell#43>", line 1, in <module>
  
floor (1,2)
  
NameError: name 'floor' is not defined
  
>>> import math
  
>>> math.floor(30.1)
  
30.0
  
>>> floor(30.9)
  
Traceback (most recent call last):
  
File "<pyshell#46>", line 1, in <module>
  
floor(30.9)
  
NameError: name 'floor' is not defined
  
>>> math.floor(23.9)
  
23.0
  
>>> int(math.floor(20.5))
  
20
  
>>> from math import floor
  
>>> floor(34.1)
  
34.0
  
>>> big=math.floor
  
>>> big(23.1)
  
23.0
  
>>> int(34.2
  
)
  
34
  
>>> from math import sprt
  
Traceback (most recent call last):
  
File "<pyshell#56>", line 1, in <module>
  
from math import sprt
  
ImportError: cannot import name sprt
  
>>> from math import sprt
  
Traceback (most recent call last):
  
File "<pyshell#57>", line 1, in <module>
  
from math import sprt
  
ImportError: cannot import name sprt
  
>>> import math
  
>>> math.sprt(2)
  
Traceback (most recent call last):
  
File "<pyshell#59>", line 1, in <module>
  
math.sprt(2)
  
AttributeError: 'module' object has no attribute 'sprt'
  
>>> from math import sqrt
  
>>> sqrt(-2)
  
Traceback (most recent call last):
  
File "<pyshell#61>", line 1, in <module>
  
sqrt(-2)
  
ValueError: math domain error
  
>>> from math import sqrt
  
>>> sqrt(4)
  
2.0
  
>>> imprt math
  
SyntaxError: invalid syntax
  
>>> import math
  
>>> cmath.sqrt(-2)
  
Traceback (most recent call last):
  
File "<pyshell#66>", line 1, in <module>
  
cmath.sqrt(-2)
  
NameError: name 'cmath' is not defined
  
>>> import cmath
  
>>> cmath.sqrt(-2)
  
1.4142135623730951j
  
>>> from math import sqrt
  
>>> from cmath import sqrt
  
>>> sqrt(3)
  
(1.7320508075688772+0j)
  
>>> from math import sqrt
  
>>> sqrt(3)
  
1.7320508075688772
  
>>> ================================ RESTART ================================
  
>>>
  
Hello, world
  
>>> ================================ RESTART ================================
  
>>>
  
What is your name? bing
  
Hello, bing !
  
>>> x= "hello"
  
>>> y= "world"
  
>>> xy
  
Traceback (most recent call last):
  
File "<pyshell#76>", line 1, in <module>
  
xy
  
NameError: name 'xy' is not defined
  
>>> x y
  
SyntaxError: invalid syntax
  
>>> x
  
'hello'
  
>>> she's mothen
  
SyntaxError: EOL while scanning string literal
  
>>>
  
>>> she\'s mother
  
SyntaxError: unexpected character after line continuation character
  
>>> "hello, world "
  
'hello, world '
  
>>> she
  
Traceback (most recent call last):
  
File "<pyshell#83>", line 1, in <module>
  
she
  
NameError: name 'she' is not defined
  
>>> 'she 's mother '
  
SyntaxError: invalid syntax
  
>>> ' she\ 's mother '
  
SyntaxError: invalid syntax
  
>>> ' she \'s mother '
  
" she 's mother "
  
>>> print ' hello world '
  
hello world
  
>>> 10000000l
  
10000000L
  
>>> print ' 10000L '
  
10000L
  
>>> print " 10000L "
  
10000L
  
>>> 10000L
  
10000L
  
>>> print 10000l
  
10000
  
>>> print repr("hello, world !")
  
'hello, world !'
  
>>> print repr(10000L)
  
10000L
  
>>> print str("hello, world !"
  
)
  
hello, world !
  
>>> temp =42
  
>>> print "the temperature is" + temp
  
Traceback (most recent call last):
  
File "<pyshell#99>", line 1, in <module>
  
print "the temperature is" + temp
  
TypeError: cannot concatenate 'str' and 'int' objects
  
>>> print "the temperature is" + `temp`
  
the temperature is42
  
>>> print "the temperature is " + `temp`
  
the temperature is 42
  
>>> name = input("what is your name ? ")
  
what is your name ? bing
  
Traceback (most recent call last):
  
File "<pyshell#102>", line 1, in <module>
  
name = input("what is your name ? ")
  
File "<string>", line 1, in <module>
  
NameError: name 'bing' is not defined
  
>>> name = input("what is your name ? ")
  
what is your name ? 1223
  
>>> name = input("what is your name ? ");
  
what is your name ? 122
  
>>> print "hello " + name "!"
  
SyntaxError: invalid syntax
  
>>> print "hello " + name " ! "
  
SyntaxError: invalid syntax
  
>>> print "hello " + name + "!"
  
Traceback (most recent call last):
  
File "<pyshell#107>", line 1, in <module>
  
print "hello " + name + "!"
  
TypeError: cannot concatenate 'str' and 'int' objects
  
>>> name = input("what is your name ? ");
  
what is your name ? 123
  
>>> print "hello " + name + "!"
  
Traceback (most recent call last):
  
File "<pyshell#109>", line 1, in <module>
  
print "hello " + name + "!"
  
TypeError: cannot concatenate 'str' and 'int' objects
  
>>> ================================ RESTART ================================
  
>>>
  
what is your name ? 123print "hello " + name + "!"
  
Traceback (most recent call last):
  
File "D:/python/test", line 1, in <module>
  
name = input("what is your name ? ")
  
File "<string>", line 1
  
123print "hello " + name + "!"
  
^
  
SyntaxError: invalid syntax
  
>>> ================================ RESTART ================================
  
>>>
  
what is your name ? 123
  
Traceback (most recent call last):
  
File "D:/python/test", line 2, in <module>
  
print "hello " + name + "!"
  
TypeError: cannot concatenate 'str' and 'int' objects
  
>>> ================================ RESTART ================================
  
>>>
  
what is your name ? "bing"
  
hello bing!
  
>>> print ''' This is a vert
  
idd
  
fdfd
  
" hello world "
  
there '''
  
This is a vert
  
idd
  
fdfd
  
" hello world "
  
there
  
>>> print " hello, \
  
world ! "
  
hello, world !
  
>>> print 'C:\\ on"
  
SyntaxError: EOL while scanning string literal
  
>>> print "C:\\ on"
  
C:\ on
  
>>> print ' hello, \n world ! '
  
hello,
  
world !
  
>>> print 'c:\nowhere'
  
c:
  
owhere
  
>>> print r'c:\nere\ndf'
  
c:\nere\ndf
  
>>> print r"this is not corrert\"
  
SyntaxError: EOL while scanning string literal
  
>>> print r"this is not corrert" "\\"
  
this is not corrert\
  
>>> print r"this is not corrert" "\"
  
SyntaxError: EOL while scanning string literal
  
>>> u'hello world !'
  
u'hello world !'
  
>>> print u'你好'
  
&#196;&#227;o&#195;
  
>>> print r'你好'
  
你好
  
>>>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-550104-1-1.html 上篇帖子: python面试题之--打乱排好序的list 下篇帖子: python小代码之阶乘求和
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表