Want to know coursera full stack web development review? we have a huge selection of coursera full stack web development review information on alibabacloud.com
Full-stack Python development: python Assignment Method, python Assignment MethodChained assignment
A = 1b = 1c = 1 # For variables with the same value, the following method can be used to assign a value for a = B = c = 1 print (id (a), a) print (id (B), B) together) print (id (c), c)
Result:
Cross assignment
# Swap m, n value m = 1n = 2 # general method te
Full-stack Python development: python string slicing,String Slicing
String slices are a type of string operators.
The Slice operation is to extract the desired substring from the string.
Syntax format: str [start, end, step]
Start position
End position (not included)
Step (1 by default)
Common Operations
[:] Extract the entire string
[Start:] extract
Full-stack Python development-Linux Command learning and pythonlinux command
Linux-everything is a file
Pwd: view the current directory
'/': Root directory
Cd: Switch the directory eg. cd/to the root directory
Ls: Check that the current root directory contains several disks and files.
Ls-l: View Details (the first character is d --> directory)
Ls-lh: user
Python full stack development 9, object-oriented, meta-class and Singleton, python meta-class
The previous series of blog posts are all about process-oriented programming. Now it's time for a wave of object-oriented explanations.I. Introduction
Object-Oriented Programming is implemented using classes and objects. Therefore, object-oriented programming is actually
Python full-stack Development 7. Module and several common modules and format knowledge supplement, pythonformatI. Module Classification
One of the reasons for the popularity of Python is that it has a large number of third-party modules, so we don't have to re-create the wheel from scratch when writing code. Many of the functions to use have been written and enc
, The output commodity list, the user enters the serial number, displays the user to select the productProduct Li = ["mobile phone", "computer", "mouse pad", ' yacht ')four, Shopping CartFunctional Requirements:
Require users to enter total assets, for Example: 2000
Display the list of items, let the user select the item according to the serial number, add the shopping cart
purchase, if the total amount of goods is greater than the total assets, indicating that the account balan
Python entry password, do not echo the password# !/usr/bin/env python = Getpass.getpass ("")Python Write code considerations:
Create an English-language Python directory for storing Python files, not in Chinese.
Create a xxxx.py file, such as test.py
Write header file:# !/usr/bin/env python # -*-coding:utf-8-*-
Rules for writing code functions
Input differences between Python2 and Python3Python2 using Raw_input ()Python3 using input ()Python
Function Call functionFunction names can be passed as argumentsfunction name () execution functionFunction name refers to the function itself#!/usr/bin/env python#-*-coding:utf-8-*-defF1 ():return "F1"#f1 = function#F1 = The surrogate function#f1 () = Execute functiondefF2 (ARG): Arg ()return "F2"#x = 123#f1 = F1 function#F2 = F2 function#F2 (x)#Execute F2 function, F1 function as argumentF2 (F1)Python Full stack
SetDefine set ([1,2,3,4]){1,2,3,4}Key values are not repeatableTernary operatorsif Else value2Depth copyImport"123"# shallow copy # deep copy Summarize:1. The depth copy does not copy the STR and the numbers, using the same area of memory.2. For list, dict,tuple copy, shallow copy only copy first layer. Deep copy copies all layers, and the last layer does not copy when it encounters a string or a number.Function programmingPython Full
1. Parameters of the function, reference 2. Lambda expression 3. Python's built-in function 4. Recursive 5. File operations1. Open FileOpen (file name/file path, open mode, encoding)Open mode: R read-only mode, default is read-onlyW write mode, unreadable; Create a file that does not exist; Clears the contents of the file if it existsX write mode, unreadable, file does not exist, create one, file exists, errorA append mode. The file does not exist, a file is created, and if the file exists, it i
return b5 6 ret = func () 2. function can not return value1 def func1 (): 2 A = 1113 b = [4]ret = func1 ()print (ret)6 # function can have no return value 7# when no return is written, the default return value of a function is ' None '3.1 def Func2 (): 2 A = 1113 b = [5]4 return# ret = FUNC2 () 6# print (ret)7# When you write only one return, the return value of the function is NoneNone4.def func3 (): = 111 = [+= ]return None# ret = func3 ()# thereturn
the name of the built-in namespace are globally scoped and can be referenced anywhere in the entire file, effectively globallyLocal scope: Local namespace, only valid locally3, stand in the global viewWhen using a name, if it is global, use the globalIf the global is not, use the built-in4, why should have scopeFor variables within a function do not affect the global5.PassFour, closed packet functionClosures: 1. Closed: Internal function2. Package: Contains a reference to a variable in the scop
') F.writelines (['1111\n','2222\n','3333\n'] # Writes a string list to a file f.write ('aaaaa\nbbbb\nccccc\n')Summary:W: Write-only mode1. When the file is present, empty2. Create an empty document when the file does not existAppend Mode (a)#A: Append write mode only#Note:#Create an empty file when the file does not exist#when the file exists, the cursor runs directly to the end of the fileF=open ('Access.log', mode='a', encoding='Utf-8')#print (f.writable ())#f.readlines () #报错F.write ('555555
the end condition.Summarize:1. Recursion must have a definite end condition2. The size of the problem should be reduced every time the next recursion is entered3. No tail-recursive optimizations in Pythonanonymous functionsWhat is anonymous function keyword lambdaanonymity means no name . def func (x,y,z=1): return x+y+z anonymous lambda# has the same scope as a function , but anonymity means that the reference count is 0 and is used once to release, unless it has a name func=Lambda x,y,z=1:
* Specifies the length, from the beginning of the truncation, do not specify the length, from the current position to the end of all removedF.writable ()#determine if it can be writtenIii. Modification of documentsHere's a simple way to implement a file modification:#File ModificationImprot os #这里导入了os模块去改文件名f_name='C:\\users\\administrator\\desktop\\3.txt'F_new_name='%s.new'%F_nameold_str='Xinjiang'New_str='Beijing BJ'F= Open (File=f_name, mode='R', encoding='GBK') F_new= Open (File=f_new_name
While loopWhy would there be loops like this statement?To give a simple example: we want to calculate the number of even numbers within 0-100, and this time we need to loop this statementThen one might say, "What 0+2+4+.......+98 can be calculated?"Suddenly our condition changed: Calculate the number of even numbers within 0-10000000 andIt can be imagined that this is how a workload, the cycle is just to solve this problem.Figure:The representation of a while loop in Python is like.Grammatical f
type base data type:String:Number:Number.max_value,number.min_value.Nan is not equal to NanIsNaN (' Test ') #trueInfinityBoolean:Null:Undefined:Reference data type:Array: ArraysString:Date:Object:4) Data type conversion
Number + String : Number converted to string
Number + Boolean: True converts to 1,false to 0
String + Boolean value : Boolean converted to string true or False
Convert to String: toString ()
Convert
27. File A.txt content: Each line content is the product name, the price, the number.Apple 10 3Tesla 100000 1MAC 3000 2Lenovo 30000 3Chicken 10 3Through the code, build it into this type of data:[{' name ': ' Apple ', ' price ': Ten, ' Amount ': 3},{' name ': ' Tesla ', ' price ': 1000000, ' Amount ': 1} ...] and calculate the total price. "ImportOs,relst=[]with Open ('C','R', encoding='Utf-8') as F1:dic= {} forLineinchF1:li= Re.sub (r'\s{1,}',',', line). Strip (',') dic['name'],dic[' Price'
20. Determine whether a number is a narcissus number, the number of daffodils is a three-digit, three-digit each of the three-square and also equal to this number. That number is a number of daffodils, for example: 153 = 1**3 + 5**3 + 3**3num = input (" Please enter a three-digit number:"= Int (num[0]) * * 3 + int (num[1]) * * 3 + int (num[2]) **3if
int (num) = = s :print(" Narcissus number ")Else : Print (" no ")Python3.6 full
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.