Winter vacation Python Tour
The club requires self-study of Python, and the card is played every three days. It can be said that it is very friendly to lazy people like me who have no motivation to learn.)
1.23~1.25
The 23rd was very motivated, but I touched it later(
Next time, you must not be so degenerate. You learn very little
Chapter 1 starting
-
First of all, I built an extremely important programming environment, which is not just a hand
-
After all, I've studied C, and there's no problem with Hello World (it's so comfortable without a semicolon)
Chapter 2 variables and simple data types
-
After learning the variable section, the mistakes are really ugly(
-
After learning the section of string, I learned the method, which is the operation that Python can perform on the data, such as in name In title(), the period after name (.) Let Python perform the operation specified by the method title() on the variable name. Each method is followed by a pair of parentheses because methods usually require additional information to complete their work. This information is provided in parentheses. The function title() requires no additional information, so the parentheses after it are empty.
-
+The number can splice strings
Line breaks are the same \ n
\t is a tab character that aligns text vertically in columns without using a table
-
White space refers to any non printed characters, such as spaces, tabs, and line breaks.
White space is very important. Delete the extra white space.
Get the method strip(). When it exists, it can temporarily delete the excess blank. Without it, there is still blank. What to do? Save the result of the deletion operation back to the variable, such as:
hahaha=hahaha.rstrip()
-
title() changes the first letter of each word to uppercase.
upper() all uppercase
lower() all lowercase
Lrsrip () only goes to the front blank
rstrip() only goes to the back
strip() is removed from the front and back
-
Now let's know a single quotation mark and a double quotation mark.
My suggestion is to use double quotation marks. Because you can put single quotation marks in double quotation marks, otherwise message = 'One of Python's strengths is its diverse community.' Where did you say it ended?
-
I don't think it's necessary to master some things in Python 2(
-
integer
There is addition, subtraction, multiplication and division, and 3 / 2 = 1.5!!!!!!!!
Use to represent the power, for example, 5 * * 6 represents the 6th power of 5
-
Floating point number
Python calls numbers with decimal points floating-point numbers
Can calculate without brain
As a result, the number of decimal places may be uncertain. After all, floating-point numbers are actually approximate calculations in computers
>>> 0.2 + 0.1 0.30000000000000004
But isn't this really a suction?!
-
Using str() to convert format to avoid type error
For example, the following error example
age=18 message = "Happy " + age + "rd Birthday!"
The format of age is numbers and the other two are strings. python doesn't know whether you intend to add and subtract 23 and strings or use them for character addition and subtraction.
-
In Python 2... (delete line) get out((
-
Python comments use # instead of/*
-
Python Zen (see for yourself)
>>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. #More beautiful Explicit is better than implicit. #Clearer Simple is better than complex. #Simpler Complex is better than complicated. #Choose the simplest among the complex Flat is better than nested. #Less nesting Sparse is better than dense. #Don't be too dense Readability counts. #Readability counts Special cases aren't special enough to break the rules. #Exceptions are not enough to break the rules Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. #Don't ignore mistakes unless you deliberately In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. #When there are many possibilities, try to find a unique and obvious solution Now is better than never. Although never is often better than *right* now.#Think about it before you start If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea.#A clear plan is a good plan Namespaces are one honking great idea -- let's do more of those! #Namespace??? It's a good idea. Use it more >>>