当前位置:网站首页>4.12 input() input function and comments
4.12 input() input function and comments
2022-06-30 15:16:00 【Andy Python learning notes】
Python Knowledge framework diagram :

4.12.1 Built in functions
Definition : The built-in function is Python Self contained functions , install Python You can use it directly .
grammar : Function name ( Parameters ) for example :print(‘520’)
4.12.2 input( ) Input function
print( ) and input( ) Are built-in functions .
print( ) Output function .
input( ) Input function .
【 Experience code 】
name = input(' Please enter your name :')
print(name)
【 Terminal output 】
Andy
Run the above code , A blank box will appear at the top of the page ;
I type my name in the box Andy , Then press enter ;
Name I entered Andy Will be input( ) Function receive ;
Then assign the received content to the variable name;
use print( name ) Call variables name, Name I entered Andy It is displayed at the bottom of the code box .
This completes the input and output of the computer .
The simple understanding is : function input( ) After the function , The computer asks you to enter your name , After you enter your name, the computer receives your name and stores it , And then use print( ) The function outputs the name you just entered , The communication between human and computer is simply completed .
input The contents in function brackets are suggestive , Will not be output by the program .
In the code above, only Andy , Please enter your name : This string of characters is not output .
4.12.3 input The input content data type of the function is string
# use input Function to enter a Chinese sentence , And assign to variable
gift = input(' What do you want for Valentine's day ?')
# Check the variable
print(gift)
# View data types of variables
print(type(gift))
【 Terminal output 】
The roses
<class ‘str’>
The first line outputs The roses It's what I entered ;
The second line class ‘str’ Indicates what I entered The roses The data type is string .
# use input Function to enter an integer , And assign to variable
int_1= input(' What's your favorite number ? Please enter an integer :')
# Check the variable
print(int_1)
# View data types of variables
print(type(int_1))
【 Terminal output 】
7
<class ‘str’>
The first line outputs 7 It's what I entered ;
The second line class ‘str’ Indicates what I entered 7 The data type is string .
# use input Function to enter a floating point number , And assign to variable
float_1= input(' What's the oil price today ? Please enter a floating point number :')
# Check the variable
print(float_1)
# View data types of variables
print(type(float_1))
【 Terminal output 】
8.4
<class ‘str’>
The first line outputs 8.4 It's what I entered ;
The second line class ‘str’ Indicates what I entered 8.4 The data type is string .
Through the above 3 Segment code , We found that , No matter what type of data we enter at the terminal ,input After the function receives , The resulting data types are strings .
Practice after class 1
The completion code , use input( ) The function inputs two integers , Then output the sum of two integers , Be careful :input The data type of the input content is string .
''' use input The function inputs two integers , And assign to variable First integer input :10 Second integer input :20 '''
# Calculate the sum of two integers
# Output this sentence as it is :10+20 be equal to 30
Practice after class 2
# My salary is... Per month 9000 element , Create a new variable to store salary
# input Function to enter your daily consumption , Create a new variable to store the input content
# Calculation 30 How much money do you have left in days ?
# Original output :30 Days later, I still have xxx element .
4.12.4 Basic knowledge of : notes
Comments explain the code , Will not be run by the program .
There are three ways to annotate :
Method 1 :#
Method 2 :'''
Method 3 :"""
The above punctuation marks are input under the English input method , Because I write notes in the text input box , Not in code box , So the display is different .
Method 1 :#
# This is the first line of comment
# This is the second line of comment
Method 2 :'''
''' This is the first line of comment This is the second line of comment '''
Method 3 :"""
""" This is the first line of comment This is the second line of comment """
边栏推荐
- It's so brain - burning that no wonder programmers lose their hair
- 1062 talent and virtue (25 points)
- Scattered knowledge of C language (unfinished)
- CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015
- Don't fight for big companies
- Sum of CCF digits (full mark code + problem solving idea) 201512-1
- Using member variables and member functions of a class
- On which platform is it safer to buy Treasury reverse repo?
- IO interview questions
- G - navigation nightare
猜你喜欢

Web technology sharing | whiteboard toolbar encapsulation of Web

Teach you a learning method to quickly master knowledge

Some reference routines for cache update

How does sd-rtn ensure the high availability of RTE services after infrastructure failure

Review 2021, embrace change and live up to Shaohua

Anyrtc implements application scenarios based on webrtc

Shift operator (detailed)

Sum of CCF digits (full mark code + problem solving idea) 201512-1

CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015

CCF Z-scan (full mark code + problem solving ideas) 201412-2
随机推荐
001 basic knowledge (unfinished)
Introduction to using 51 single chip microcomputer to control steering gear
Examples of bubble sorting and matrix element screening in MATLAB
Some reference routines for cache update
How to do a good job in high concurrency system design? I have summarized three points
What would you choose between architecture optimization and business iteration?
1149 dangerous goods packaging (25 points)
CCF access control system (Full Score code + problem solving idea) 201412-1
文本匹配——【NAACL 2021】AugSBERT
Anyrtc implements application scenarios based on webrtc
Developer practice - the future of Agora home AI audio and video
Win10 backup backup shows that creating a shared protection point on the shadow failed
Industry analysis | the future of real-time audio and video
Npumcm selection question 3 and acmc2020a
At the beginning of the 2022 new year, I will send you hundreds of dry articles
How many questions can you answer for the interview of Mechanical Engineer?
NPM install --global --save --save dev differences
I - constructing roads
Repair of incorrect deletion of win10 boot entry
1151 LCA in a binary tree (30 points)