The 2nd lesson of "Julyedu-python Basics":

Source: Internet
Author: User

Outline

Variables and types
Common string Handling
Conditional judgment
Loop control
Function

Variable and type basic variable types

For Python all objects are class containers that inherit from object:

Integer print (type (1234)) <class ' int ' > lists <class ' list ' > Print (Type ([1, 2, 3, ' A ', ' B '))
Floating point print (Type (123.)) <class ' float ' > tuple <class ' tuple ' > Print (Type ((1, ' abc '))
String print (Type (123.)) <class ' str ' > Set <class ' Set ' > Print (Type (set ([' A ', ' B ', 3]))
Boolean dictionary <class ' dict ' > Print (Type ({' A ': 1, ' B ': 2}))
Null value
Function
Module
Type
Custom Types

Variable definition

The value that the variable is stored in memory. This means that there is a space in memory when creating variables.
Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in memory.
Variables can specify different data types, which can store integers, decimals, or characters. (Weak type)

Assigning values to variables

Each variable must be assigned before it is used, and the variable will not be created until the variable is assigned. (Important!!! )
The equals sign (=) is used to assign a value to the variable, the left side of the equals (=) operator is a variable name, and the right side of the Equals (=) operator is the value stored in the variable.

Common string Handling

Remove spaces and special symbols: strip, Lstrip, Rstrip
Copy string: str1 = str2
Connection string
STR2 + = str1
New_str = str2 + str1
Find string: pos = Str1.index (STR2)
Compare strings: CMP (STR1, STR2)
String length: Len (str)

Uppercase and lowercase conversions
U_str = Str.upper ()
L_str = Str.lower ()
Initial capital: Str.capitalize (); String.capword (str)
Splitting and merging strings: Split, Splitlines, join
Type conversions: int, float conversion
formatting strings

String test
Str.startwith (prefix)
Str.endwith (suffix)
Str.isalnum () # is full of letters and numbers, and has at least one character.
Str.isalpha () # is full of letters and has at least one character.
Str.isdigit () # is full of numbers and has at least one character.
Str.isspace () # is full of whitespace characters and has at least one character.
Str.islower () # Letters are all lowercase
Str.isupper () # are all uppercase letters?
Str.istitle () # Whether the initial letter is capitalized

Conditional judgment

Truth judgment
if x = = True:
If x:
If not x:
Null value judgment
If X is None:
If not x:
Comparison
If a = = B:
If a > B:
...

Loop control

For loop
For I in range (begin, end, steps): <=> for (i = begin; I < end; I + = steps)
While loop
While condition judgment:
Loop nesting
Loop control
Break
Continue
Pass

Function

function definition Format
Default parameters
Variable parameters: *args, automatically assembled into a tuple
Keyword parameter: *args, automatically assembled into dict
Named keyword parameters
Function call
Function name (parameter name)
Module name. function name (parameter name)
Call with parameter name
What is recursion?

The 2nd lesson of "Julyedu-python Basics":

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.