Wednesday, November 29, 2023

Day 1 - print & input functions

Using replit.com for my py coding and execution.

# --------------------------------------- print() ----------------------------------------------

#print() function to print the contents in the console output

print("Hello World")

# To add 2 strings and print, we can use the + operator. Note that both the values in the operation are strings.

print("Add 2 strings using '+' operator: 'Ram' + 'sundar' will give: " + "Ram" + "sundar")

# From the above 2 statements, we can see that Strings can be represented in single or double quotes


# --------------------------------------- input() ----------------------------------------------

#input() function to get input from end user and store the string in a variable and printing it

# The input values are always string. So if we need an int/float, we should convert the data type.

user_name = input('Enter your name')

print("Name: " + user_name)

#OR as below without using the help of a variable

print ( "Name" " + input('Enter your name'))

age = int(input("Enter age"))

print ("Age is :" + str(age))


-----------------------------------------End of Day 1 ----------------------------------------------





No comments:

Post a Comment

Day 2 - Primitive Data Types

#-------------------int, float, boolean and String, len(), type() ------------------------------ Retrieving each char from String # String: ...