Basics of Input/Output
Taking input from user –
Python provides us with two inbuilt functions to read the input from the keyboard.
- raw_input(): This function works in older version (like Python 2.x). This function takes exactly what is typed from the keyboard, convert it to string and then return it to the variable in which we want to store. For example:
# Python program showing
# a use of raw_input()
g = raw_input("Enter your name : ")
print g
- input(): This function first takes the input from the user and then evaluates the expression, which means Python automatically identifies whether the user entered a string or a number or list. For example:
# Python program showing
# a use of input()
val = input("Enter your value: ")
print(val)
Note: For more information, refer Python input()
and raw_input()
.
Printing output to console –
The simplest way to produce output is using the print()
function where you can pass zero or more expressions separated by commas. This function converts the expressions you pass into a string before writing to the screen.
# Python 3.x program showing
# how to print data on
# a screen
# One object is passed
print("w3wiki")
x = 5
# Two objects are passed
print("x =", x)
# code for disabling the softspace feature
print('G', 'F', 'G', sep ='')
# using end argument
print("Python", end = '@')
print("w3wiki")
Output:
w3wiki
x = 5
GFG
Python@w3wiki
How to Learn Python from Scratch in 2024
Python is a general-purpose high-level programming language and is widely used among the developers’ community. Python was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code.
If you are new to programming and want to learn Python Programming from Scratch, then this complete 2024 guide is here to help you. Whether you are an experienced programmer or new to the programming world, this guide will help you with the knowledge and resources needed to get started with Python Language.