Install Pycharm Professional Edition, do not Chinese
To write code that supports Linux and version 2.0 needs to be annotated at the beginning
#/usr/bin/env python
#-*-Coding:utf-8-*-
Operator
The result is a value
Arithmetic operations
A = 10*10
Assignment operations
A = A+1 is A+=1
The result is a Boolean value (return True or FALSE)
Comparison operation
A = 1>5
Logical operations
A = 1>6 or 1==1
Member operations
A = "Tom" in "L"
Basic data type (not all, supplemented later)
Digital
5 v= name.bit_length () int("1101",base=2 ) #把1101转换成2禁止 Base= + converts a to 16 binary print (v) # In Python3, int can represent all numbers, no matter how long, and after more than a few bits in the python2, they become long .
String
Name ="Alex"v=name.capitalize () #首字母变成大写print (v) name="Tom"v= Name.find ("T",) #查找alex中a所在的位置. Print (v) name="ALeA"v=name.casefold () #casefold all the letters into lowercase capitalize and all the letters to lowercase but the former more awesome print (v) #后者只能识别自己国家的前者可以识别所有name1="Tom"v1=Name1.upper () #upper all into uppercase print (v1) test="Tom"v= Test.center ( -,"in"The #center represents a fill of 20 for the total length of the representation that is around the word list can only be one character print (v) name="Tom"v= Name.count ("T",0,2) #去字符串中寻找子序列出现的次数0 2represents the print (v) name within the range="Tom"v= Name.endswith ("m") #以m结尾 return ture value v= Name.startswith ("T") #以t开头 translation ture value print (v) name="I am {name1},age{a}"v= Name.format (name1 ="Tom", a= at) #将name1, A is replaced with the specified value print (v) name="! 123tom"v=name.isalnum () #检查字符串中是否只包含数字 letters can also return a value of ture or Falseprint (v)
#name ="Tom"# if "T" inchName: If T executes in Name 1 does not execute the * print ("1")# Else: # Print ("2")# if "T"NotinchName: If T does not execute in Name 1 does not execute the * print ("1")# Else# Print ("2") # User="Tom"# pwd="123"# v= user=="Tom"and PWD = ="123"Or1==1and PWD = ="456"and1==2#等于Ture if trub# print (v) is established between and
Python Basics 2