Python Study the next day

Source: Internet
Author: User
Tags arithmetic logical operators

Python Development Ide:pycharm,eclipse

#下载专业版而且不要汉化33

An. operator

1. Arithmetic operator: +-*/*%//

2. Member operator: in not in result is Boolean type

Name='Li Jongdan'#if ' Li Dan ', the error is output#' Li Jongdan ' Dan is a substring, a subsequence#Ctrl + after selection? For all commentsif "is" inchName:Print("OK")Else:    Print("Error")if "Dan"   not inchName:Print("OK")Else:    Print("Error")

3. Comparison operators: = = > < >= <=! = does not equal <> not equals not to negate

4. Logical operators: And OR

user="Alex"pwd="123"v=user==" Alex "  and pwd=="123"or and pwd=="  728684"print(v)

Add: priority is calculated in parentheses first
True before or after or whatever is true behind
False and no matter what is behind it is false

5. Assignment operator + = *=-=/=

Summarize:

The result in the operator is the value: arithmetic operation assignment; result is Boolean comparison operation logical operation member operation

Two. Basic data type CTRL + LEFT mouse button

1. All the functions of the digital int are placed in int

#Python3, all shaping numbers are shaped int#Python2, small numbers are shaped int, over range is long#Shaping int#string str#Lists List# Tuple tuples#Dictionary dict#boolean bool#int function 1 conversion Converts a string to a numberA="123"b=Int (a) b=b+100Print(b)#int function 2 Converts the other binary to 10 binarynum="0011"v=int (num,base=2)Print(v)#the function of int 3 bit_length The binary of the current number, represented by at least n bits#1 1#2 Ten#3#4Age=4R=age.bit_length ()Print(r)

2. String str

test="Alex"#function 1 Initial capital letterv=test.capitalize ()Print(v)#Convert all letters to lowercase, casefold more powerful, many unknown correspondence can be converted to lowercasev1=Test.casefold ()Print(v1) V2=Test.lower ()Print(v2)#Set the width and center the content#After the parameter does not write the default is blank, support to fill a characterV3=test.center (20,"*")Print(v3)#Count occurrences, support characters and sub-sequences, and two parameters behind indicate start and end positions#start position is starting from 0V4=test.count ("e", 2,3)Print(v4)#indicates what end or what to start with, can be a character and a stringV5=test.endswith ("a")Print(V5) V6=test.startswith ("a")Print(V6)#find the first satisfying condition and get the position interval for the character or subsequence to >=0 and <1#not found, then-1V7=test.find ("e", 0,1)Print(V7)#formatting: Replacing the contents inside the brackets#test= ' I am {name},age={a} '#print (test)#V8=test.format (name= ' Alex ', a=19)#print (V8)test='I am {0},age {1}'Print(test) V8=test.format ('Li Jongdan', 19)Print(V8)#formatting, different ways of passing valuestest='I am {name},age={a}'V9=test.format_map ({'name':'Alex','a': 19})Print(V9)#Index is similar to find in the location of the index. #The difference is that find can not find the -1,index can not find a direct error#V10=test.index ("E", 0,1)#Print (v10)#determines whether a string consists only of numbers or letterstest="dsidhsi890+"v=Test.isalnum ()Print(v)

Complements the use of the tabulation function

# the tab \ t uses, along with the preceding string, a total of n lengths, enough to be padded with blanks test="useranme\temail\tpassword\nlzd\[email protected]\ T123\nlzd\[email protected]\t123\nlzd\[email protected]\t123\n"v=test.expandtabs  Print(v)

3. List of lists

4. Tuple tuples

5. Dictionary Dict

6. Boolean bool

Python Study the next day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.