18
# too many pictures, see link and text in detail
One, daily interview (Knowledge Review)
1. Q: After executing the following code, what are the contents of l,m?
def func (m):
For k,v in M.items ():
M[K+2] = v+2
m = {1:2, 3:4}
L = m # shallow copy
L[9] = 10
Func (L)
M[7] = 8
Print ("L:", L)
Print ("M:", m)
# error: Dictionary changed size during iteration
# (python3.6) You cannot modify the size of a list or dictionary while iterating through a list or dictionary
2, =, slice, copy, deepcopy
Import Copy
List1 = [11, 22, [33, 44]]
List2 = List1
List3 = list1[:]
List4 = Copy.copy (List1)
LIST5 = Copy.deepcopy (List1)
List1[2].append (55)
Print ("List2:", List2) # [11, 22, [33, 44, 55]]
Print ("List3:", List3) # [11, 22, [33, 44, 55]]
Print ("List4:", List4) # [11, 22, [33, 44, 55]]
Print ("List5:", LIST5) # [11, 22, [33, 44]]
Print (ID (list1)) # 4363819976
Print (ID (list2)) # 4363819976
Print (ID (list3)) # 4363820104
Print (ID (list4)) # 4363820040
Print (ID (LIST5)) # 4363834760
# The first several are copies of a connection address, the original list after the change, the values of these lists according to the connection value, the corresponding changes. The latter (deep copy) is the beginning of a self-built space, the original list of values change, it does not follow the change.
3. Annotations (Normalization)
1. # TODO: Prompt Before you pass git (not considered here)
2, in-line comment Balabala # Balabala
3. Single line Comment # Balabala
4, multi-line Comment ""
5, function, class internal comment
def foo (name, age):
"""
What is this function for?
:p Aram Name: User name, must be a string type
:p Aram Age:
: Return:none
"""
Print (name)
Print (age)
4. Join the elements of the connection list (only strings can be concatenated)
List_tmp = [11, 22, 33, 44]
LIST_TMP2 = ["Alex", "DSB", "hehe", "haha"]
Ret1= "". Join (LIST_TMP2)
Ret2= ",". Join ([STR (i) for I in List_tmp])
Print (RET1) # Alexdsbhehehaha
Print (Ret2) # 11,22,33,44
5. Three-dimensional expression in Python (ternary operation)
# if n > M, I'll assign the value of N to x, or I'll assign the value of M to X
n = 10
m = 5
x = N if n > m Else m
Print (x) # 10
Ii. content of today
Blog Link: https://www.cnblogs.com/liwenzhou/p/8004649.html
1. What is JavaScript?
A lightweight programming language; A scripting language that runs on a browser.
node. JS can write back-end.
2. What does JavaScript learn?
1. Grammar Basics
2. BOM (Document Object model)---manipulate browser with JS code
3. DOM (Browser object model)--manipulating HTML documents with JS code
3. How does JavaScript work?
1. How to import:
1. Write a script tag in the HTML file and write the JS code directly in the script tag
2. Write the JS code in a separate JS file and then import it via the SRC attribute of the script tag
2. You can directly run JS code directly in the browser's console window
3. node. js Run JS file * (now understand)
4. What does JavaScript learn?
0. Grammar rules
1. Single-line comment//
2. Multi-line Comment/* Multiline comment */
3. Terminator;
1. Variables
1. Variable Name: can use _, number, letter, $ composition, cannot start with a number
1. Variable names are case-sensitive.
2. It is recommended to use camel-style naming rules.
3. Reserved words cannot be used as variable names.
2. Declaring variables
1. var
2. Let (ES6 new): Declared variables are only valid within the block of code where the Let command resides.
For example, a For loop counter is good for using the Let command.
3. Const (ES6 New): Used to declare constants. Once declared, its value cannot be changed.
2. Data type
1. String
Common properties and methods for strings
# substring does not support negative numbers, slice supports negative numbers, typically slice slices
Substring (0,-2), Substring ( -2,0)->substring (0,0)
# SHIFT + ENTER line break
• (anti-quote) does not error in ES6; • Error, according to the above set to ES6 or at the beginning of the JS file add a line:
/* Jshint Esversion:6 */
A template string was introduced in ES6. The template string, which is an enhanced version of the string, is identified with an inverse quotation mark ('). It can be used as a normal string, or it can be used to define a multiline string, or to embed a variable in a string.
2. Values
1. JS does not distinguish between integral type and floating point type, called numeric type
2. Nan indicates that a value is not numeric (it is a numeric type, but it is not a number and not a digit; Nan may occur when a string is converted to a number)
3. Convert data from a string type to a numeric value
parseint ("100")
Parsefloat ("11.11")
3. Boolean Value ("" (empty string), 0, null, undefined, Nan are false)
True False
4. Null
When you manually empty the value of a variable name=null
5. Undefined
Variable light is declared but not assigned; When a function has no explicit return value
6. Object (All things in JavaScript are objects: strings, numbers, arrays, functions ...) In addition, JavaScript allows custom object) objects with special data types with properties and methods
1. Arrays
Todo:sort (Details see tomorrow's Course)
2. Built-in properties and methods for arrays
# sort converts the elements in an array into strings, and then a comparison of one by one
Console.log () equivalent to print ()
Determine the type of a variable:
Typeofnull-Object
typeof [11,22]--Object
typeof Undefined--undefined
# typeof is a unary operator (just like ++,--,! ,-the unary operator), is not a function, nor is it a statement.
3. Operators
1. Arithmetic operators
% take-up
2. Logical operators
3. Comparison operators
1. Weak equals "5" = = 5--and true
2. Strong equals "5" = = = 5--and false
4. Assignment operators
4. Control statements
1. If ... else ...
2 ... else if ... else ...
3. Switch () {
Case 1:
...
Break
}
# switch is used primarily for a variable with a value in the comparison case
#一定要加break, or the program will continue to execute the statements in the subsequent case
4. For
5. While
6. Ternary operation
5. Functions
1. Definition of functions
1. General functions
2. Functions with Parameters
3. Functions with Return values
# If return is followed by more than one value, returns the last
4. Anonymous functions
5. Self-executing function (execute function immediately)
6. Arrow functions
# If the arrow functions do not require arguments, or require multiple arguments, use () to represent the parameters section
2. js function of the Pit
1. The default return value is undefined
2. Calling the function simultaneous the argument arbitrarily
3. Only one return value
3, function built-in arguments object
4. Exercises
The basics of JavaScript syntax