Python Basics with raw input

Python Basics with raw input

In Python 2.x, you can use the raw_input() function to read input from the user. Here is a basic example:

# Ask the user to enter their name
name = raw_input("What is your name? ")

# Print a greeting
print "Hello, " + name + "!"

In this example, the raw_input() function is used to prompt the user to enter their name. The input is then assigned to the variable name. The print statement is used to output a greeting using the value of name.

Note that in Python 3.x, raw_input() has been replaced with input(). If you are using Python 3.x, you would use the following code:

# Ask the user to enter their name
name = input("What is your name? ")

# Print a greeting
print("Hello, " + name + "!")
The only difference is the use of input() instead of raw_input().

Python Basics with raw input

Facebook Reviews:

If you are a training provider

Interested to offer our courses in your own platform with Life-time Resale License?