[Python learning notes] hello,python

to configure Version: Python 3.7.6 Tool environment: Anaconda Development tool: PyCharm It's all free. It's good to find...
to configure
Try py (Interactive interpreter)

to configure

Version: Python 3.7.6
Tool environment: Anaconda
Development tool: PyCharm
It's all free. It's good to find it on the Internet. It's right to choose the automatic installation path when installing. Don't be like I can't do it well so I often come back.

To open the command window, press [Win+R] - > Enter [cmd]

It's easy to use
Computer pdf reader: rice husk reader
pdf book download address: http://soshuvip.com/
Computer software installation official account: partner God

Try py (Interactive interpreter)

I still think it's more convenient and intuitive to use my own IDLE at the beginning.

  1. number
>>> 7/3 2.3333333333333335 >>> 7/1#Return floating point number forever 7.0 >>> 7//3 #Round down 2 >>> 5**2 #Exponential operation 25 >>> x=100 #Assignment not displayed >>> 3*x 300 >>> 5+3j+2+2J #Complex number, J/j for imaginary part (7+5j)
  1. character string
>>> 'i\'m fine' "i'm fine" >>> print("hello\nworld") hello world >>> print(r"hello\nworld") hello\nworld >>> print("hello\nworld") hello world >>> print(r"hello\nworld")#r before quotation marks, restrict escape characters hello\nworld >>> print("""\ hello world\ ,python """)#"Multiline characters, wrap each line automatically, \ \ restrict wrapping" hello world,python >>> 3*"hello"+'py' 'hellohellohellopy' >>> 'py''thon' 'python' >>> x='py' >>> x[0]#Indexes 'p' >>> x[-1]#Negative number from right to left 'y' >>> x+='thon' >>> x[2:5]#section 'tho' >>> x[:-2]+x[:1] 'pythp' >>> x[100]#Beyond, baocuo Traceback (most recent call last): File "<pyshell#24>", line 1, in <module> x[100]#Beyond, baocuo IndexError: string index out of range >>> x[:100]#Slice does not report error 'python' >>> len(x)#Built in function len(), return length 6
  1. list
>>> fib=[1,1,2,3,5,8] >>> fib [1, 1, 2, 3, 5, 8] >>> a=fib#Copy variable address >>> a[0]=0 >>> fib[0:2] [0, 1]
  1. Bitwise operator
>>> b=13#1101 >>> a=9#1001 >>> a&b#Bitwise and, 1001 9 >>> a|b#Bitwise OR, 1101 13 >>> a^b#Bitwise XOR, 0100 4 >>> ~a#Reverse by bit -10 >>> a<<2#Shift, 100100 36 >>> True and False #and,or,not False

In this case, the result of a=9(1001) reversed by bit is obviously (0110), which is not consistent with the example. Search for it, and write down the conclusion first: ~ n = -(n+1)
Similarly, c=-10,~c=-(-10+1)=9

Reference: understanding of the bit by bit negation operation in Python https://blog.csdn.net/strive_chuan/article/details/79242010

  1. Keyword is,in
>>> 5 in (1,2,3,5)#Determine whether it is included in the specified sequence True >>> 1 not in(1,2) False >>> a=1000 >>> id(a)#Built in function id(), return variable address 2301116519664 >>> b=1000 >>> id(b) 2301116519696 >>> a is b#Determine whether two identifiers refer to the same object False >>> a==b True

There are some differences between "is" and "= =":
==The content is equal, and the address can be different;
is has the same content and address.

Reference: detailed explanation of the difference between is and = = in Python https://blog.csdn.net/qq_26442553/article/details/82195061

4 June 2020, 12:45 | Views: 7240

Add new comment

For adding a comment, please log in
or create account

0 comments