Write a program inside the file(with .py as extension) to get input from user and display in screenCode:
"""
Simple program to get input
to display string with input we got
giving comments
"""
design='---------------------------------------'
info = input("Enter your name:")
print(design + "start" + design)
print('Your name is:', info) #This will print 'Your name is: <<Entered name>>'
print(design , "end" , design)
- write comments, for multiple line comments, we need to start and end with triple double quotes(""")
- to write single line comments you can start with hash (#)
- you can assign a string value to variable, like
- design='---------------------------------------'
- for assigning string value you can use single quotes or double quotes on both sides as mentioned above
- to print something we need to use print function
- print function is a build-in function in python to print values
- We can directly print string values using single quotes or double quotes
- print("Welcome")
- print('Welcome')
- Concatenate string with a variable
- Assume that string John is stored on a variable called variablename now if we need to print Welcome John means
- print("Welcome",variablename) #Output will be Welcome John, an automatic space will be there if we use comma
- if we don't need space means print("Welcome"+John)
- While concatenating using +
- string + string #correct
- string + int #wrong
- int + int #correct
- Getting input
- We need to use input() function to get input from user
You can see the below video for better understanding of this post
In next post we can see about using numbers and calculations
No comments:
Post a Comment