This introduction of a simple jokes of the game, from simple input and output components. When using the keyboard to enter the user typed. Text output is displayed on the screen.
main content:
- Escape character
- Using single and double quotes string
- Use print () end shape function key parameter to skip the line feed
Source:
print("What do you get when you cross a snowman with a vampire?")
input()
print('Forstbite!')
print()
print("What do dentists call an astronaut' cavity")
input()
print('A black hole!')
print()
print('knock knock.')
input()
print("Who's there?")
input()
print('Interrupting cow.')
input()
print('Interrupting cow wh', end='')
print('-MOO!')
Character Transfer
Transfer character (escape character) so that we can print that is difficult to enter into the source code of the characters, such as the beginning of a string of single and single quotes in the end to enter a double quotation mark, the double quotation marks at the beginning and end of the string enter a single quote, you need to use the backslash.
Common metastatic character
Escape character | description |
---|---|
\\ | Backslash |
\ ’ | apostrophe |
\ " | Double quotes |
\ a | Bell |
\ b | Backspace (Backspace) |
\ n | Wrap |
\ r | Wrap |
Single and double quotes
Python in single and double quotes is no different, but the two can not be mixed quotes. In a single quoted string, it is unnecessary to escape the double quotation marks; string in double quotation marks, the need to escape single quotes, but need to be escaped double quotes.
>>> print("I am a \"Python\"")
I am a "Python"
print () parameter of the end keyword:
print () function when no string argument, a line feed is added at the end of the string.
>>> print()
print('Interrupting cow wh', end='')
print('-MOO!')
Value passed to a function call, called parameters. Passed to print () function is called Keyword argument empty string (keyword argument). end = '' in the end parameter called the keyword (keyword parameter). To a keyword argument to parameter must be entered at the front end =.
reference:
- "Python Game Programming Quick Start" fourth edition, AI Sweigart with, Li Qiang translation