Beginner python

The following just write a little C ++ and python different points

1 python is a dynamically typed language

Type the code would walk around with changes

2 python does not support the increment decrement ++ - translation of plus or minus

3 python float does not exist seems to float in fact double

4 print (type (num)) can print variable of type

5 python of the type of int also belong to the object

6 complex (square root meaningless -1) indicates how + 5j j: complex number represents a basic unit, i.e. root -1
EG: NUM = + 10.0. 5J;

7 python is an integer of 4 bytes but not unlimited length (i.e., can represent arbitrarily large number)

8 you my name is "Joe Smith" already has ""

How do we represent?
The original contents' 'we' 'to cause
that there are "" We use' 'to cause
that there are' 'We use the "" "" "" triple quotes or escape character
EG:
name =' My name IS "Ah Yang " '

9 built-in function: a function comes python means
eg: print (len (name) )

print(name[1])   结果为 打印第二个y
print(name[-1])  打印倒数第一个  ,倒数不存在倒数第0个  ==》len(name)-1

Slicing: Slice
Print (name [0: 1]) is the result of my
slices left omitted from 0 1
2 omits the right end of the last
3 are omitted: that the whole string of
multiplication of the string (and only an integer multiplication)
EG: print (name * 3) that is printed three times a name

Alternatively later use format 10 3.6
EG: NUM = 10;
A = f'num NUM = {} '
Print (A)
. 11 Boolean: python are case sensitive True (essentially 1) False (essentially 0)
EG: A = True print (of the type (A)) print (A + 1) ==> 2
12: Python default end to print \ n we do not want to let him wrap can print (a, end = '' )

13 with an input function ptython input
EG1: S = input ( "Enter a string:") // NOTE: The result obtained is a character string input
print ( "s:", s ) // If we enter the an integer print ( "s:", int (s))

14 Note: #
python2 Chinese comments may be present coding problem python2 need to add #coding: utf8

In addition to precisely 15 / // take divisible

16 size comparison print (a <b <c) represented b> a and b <c c ++ compile, but not run, java directly error
our best print (a <b and b < c) print (a <b or b <c) print (not a <b) a = "hehe" b = "hehe" print (a = b)

 不论c++ / java  /python 字符串比较大小  都按字典序比较

List 17 / tuple / dictionary
1 List [] array does not exist python python concept called list (list is essentially an array, linked list not)
A = [4,3,2]
Print (A [1])

2 元组()  (tuple)   元组元素不可修改,列表元素可以修改,列表和元组的内部类型完全可以不一样
b= (2,3,4,56,7)
print(b[1])

3  字典 {本质为键值对的结构}  {}
a={  'ip' : '127.0.0.1' ,  
	'port' : '9090'
  }

print(a['port'])//即用哈希表存储

18 references (ie variable names just cited, namely a label, do not create a space)
A = 100
b = A;
# the above mentioned id is a built-in function can view the variable identity (logo only, and it does not matter which memory is stored)
Print (the above mentioned id (A))
Print (ID (B))

Python 20 is retracted by the strict requirements python code block indention pyhton {} function without the direct use of:

Indent block 1
EG: IF (RET == '1'):
Print ( "God the offer")
else:
Print ( "Sell Apple")
Print ( "Use the peer Sell") // else it belongs indention

2  多分支  只能这样写
	if ret == '1':
	    print(1)
	elif ret == '0':
	    print(0)
	else:
	    print(-1)

21 loop
. 1 the while
EG: NUM = 10
the while NUM> 0:
Print (NUM)
NUM -. 1 =

2 for(相当于范围for)
eg:  for  num in range (0,10):  #左闭右开
	print(num)
遍历列表 :
	eg:  for  num  in a :
		print(a[num])		

22 pass sentence
sometimes need consequently not do it, but we had to meet the needs of the syntax to use pass

Analytical list 23 (the list is derived)
A = [1,2,3,4,5]
B = []
for NUM A in
C * NUM = NUM
b.append ©
Print (B)

或者 b =[num ** 2 for num in a if num %2 == 1]    print (b)

24 function
def create a function
EG; def the Add (X, Y)
return X + Y

Published 90 original articles · won praise 13 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_44030580/article/details/103916638