In fact, learning every language, you can find a very happy learning method. Be interested, have fun, will always want to learn. Knowing print (), input (), if/else can be a primitive game.
Print () # Prints the function, prints out the information input() # Prints the information, and asks for a paragraph, and puts the phrase. If 1 + 1 = = 2: Print (' I am true, if it equals 2, it will print me!!! ' Else: Print (' I am false, if the sum is not equal to 2, it will be printed I ~ ~ ~ ') # conditional judgment statement
Then we can start the game with the 3 bif functions we learned above:
Print ('-----------wordgame-----------') number = Int (input ("Guess what the System gives:")) If # = = 8: print ("Wow, guess!!") else: print ("Guess wrong, the system gives the number is 8!") ")
We can disassemble the function to analyze
Print function, we print a game title via print
Print ('-----------wordgame-----------')
The input function, which displays the string on idle and lets the user enter information to save the message to number
Note: input is the string type by default, and here we use INT () to convert the input information directly to the int type when we enter it.
Number = Int (input ("Guess what the System gives:"))
Conditional judgment statement, in Chinese to indicate that if number is 8, print "Wow plug, guessed", whether the printing "wrong!" ”
If number = = 8: print ("Wow, guess!!") else: print ("Guess wrong, the system gives the number is 8!") ")
Flowchart of the program
If the decomposition of the function is still unclear, then the drawing will make people easier to understand, write the program drawing, the idea will be very clear, and the things done are not easy to mistake.
Python's bif
What is BIF? bif is built-in Functions, built-in function. In order to facilitate the programmer to quickly write a script program (the script is fast!!!) Python provides a very rich built-in function that we just need to call directly. For example, the function of print () is "printing to the screen", the function of input () is to accept user input (note: Python3 's input () replaces Python2 's Raw_input ())
Python has a total of 68 bif
In Python's idle, you can enter Dir (__builtins__) to see a list of the built-in methods provided by Python (note that there are two underscores before and after builtins) where lowercase is bif. If you want to see a specific BIF function, such as input (), you can enter help (input) in the shell, you can get the BIF function description.
In Python's view: ' AAA ' is not the same as ' AAA '
' AAA ' and ' AAA ' are completely different two names, so be careful when programming, but Python will help solve these problems, for example, if the identifier is already assigned before it can be used in code, the unassigned identifier will result in a run-time error, so you can quickly find the error based on experience.
Indentation in Python is important
Indentation is the soul of Python, and the indentation requirements make Python's code look very streamlined and layered. So be very careful with the indentation code in Python, and if there is no proper indentation, what the code does may be a far cry from what you expect (as in the C language, the parentheses are in the wrong place).
If you enter the colon ":" in the correct location, idle will indent the next line automatically!
Python = and ' = = '
In C, if the IF (c = = 1) is written as if (c = 1), the program is completely out of the hands of the program, but in Python it is a syntax error. Because Python does not allow the if condition to be assigned a value, if C = 1: It will be an error!
= 1: syntaxerror:invalid syntax
Summary of this learning function
| Print () |
Print function |
| Input () |
Input function |
| Dir (__builtins__) |
View BIF |
| Help (print) |
Help |
| If and Else |
Judgment statement |
Category: Python
Python Learning notes (1)