Input variables into python | Laptrinhcanban.com

HOME › >>

Input variables into python

Posted at: https://laptrinhcanban.com/en

Instructions on how to input variables into python . You will learn how to input a variable’s value from a keyboard using the inpput() function in python after this lesson.

Input variables into python

To import variables in python we need to use a built-in function called inpput () function in python .
The input () function will help us enter input from the keyboard and assign that value to the variable with the following syntax:

variable= input()

Inside:

  • input used to call the function. When the function is called, an input line will appear so that the user can input from the keyboard.
  • variable is set according to the Python Variable Naming Rule that you learned in the article What is Variable in Python.

After the user can input from the keyboard, the input string will be assigned variable as the string data type.

You can also use the following syntax to make the input screen more beautiful:

variable= input(">>")

For example, we have a program to enter the name and print it to the screen as follows:

print ( "Please enter your name :" ) 
name = input ( ">>" )

print ( "Enter your age:" )
old = input ( ">>" )

user = "\n Your name :" + name + "\n Your age:" + old
print (user)

Save the above program as user.py and run it on Anaconda Prompt. The result will be as follows:

Enter variables in python

Summary

Above, Kiyoshi explained how to import variables in python. To better understand the lesson content, practice rewriting today’s examples.

And let’s learn more about Python in the next lessons.

URL Link

https://laptrinhcanban.com/en/python/nhap-mon-lap-trinh-python/bien-trong-python/nhap-bien-trong-python/

Thank you for reading and please Like & Share for other friends to learn.
">

HOME  › >>

  • Recent Posts
Profile
きよしです!笑

Author: Kiyoshi (Chis Thanh)

Kiyoshi was a former international student in Japan. After graduating from Toyama University in 2017, Kiyoshi is currently working at BrSE in Tokyo, Japan. Kiyoshi là một cựu du học sinh tại Nhật Bản. Sau khi tốt nghiệp đại học Toyama năm 2017, Kiyoshi hiện đang làm BrSE tại Tokyo, Nhật Bản.