Outputs

We have not seen how to show the data that you are working with, so to do it you will need the function "print(x)", where x is the variable that you want to print. You can also work with the instruction just as "print('Hello World!')".

If you want to print 2 or more elements, you can use "print(x,y)", but keep in mind that it means "print(str(x)+' '+str(y))". I personally prefer the string method "format", so you will code "print('{} {}'.format(x,y))", I feel that I have more control of the empty spaces, it is up to you.

A = "Hello"
print(A+' World!')  # Hello World!

B = ['Hello', 'World!']
print(B)            # ['Hello', 'World!']

# I didn't like 2020
print("I didn't like",2020)

# My first name is Albert, and my last name is Einstein.
print("My first name is {}, and my last name is {}.".format("Albert", "Einstein"))

# Today is February 4th, 2021.
print("Today is {m} {d}{e}, {y}.".format(d=4, e='th', m='February', y=2021))

End of the print statement

By default python’s "print(x)" function ends with a newline. If you dont want the termination of the "print(x)" statement to be a "\n", you need to change the parameter "end", so you will use "print(x, end=y)"

# Prints "Hello World!\n\nPython@HeyUalabi"
print('Hello', end=' ')
print('World!\n')

print("Python", end="@")
print("HeyUalabi")

Inputs

Now, to introduce data to the computer from the terminal, you will need the command "var = input(x)", where "x" is the text that will be shown to ask for the data (x = '' by default), and "var" will be tha variable that stores the data. Its really important to notice that input returns a string, so to read integers or other data type, you will need to cast it (use "int()", "float()", "bool()"...).

If you want to read multiple variables at the same line, its really commmon that the variables are separated by an empty space, so you will need the string method "split" that returns a list. If all the elements are the same type, you can use the functio "map(x,Y)", that it will basically cast all the elements of "Y" into the data type "x".

"map(x,Y)" returns a strange data type of "< class 'map' >", just keep in mind that its better to cast it into a list, so most of the times I use "var = list(map(x,Y))". But if you know the number of elements that are being casting, you can just use "month, year = map(int, ['2','2021'])".

# If you receive and integer, remember to cast it into an int
number = int(input('Give me a number: '))
print("The square of",number,"is:",number*number)

name = input('Give me your name: ')
lastname = input('Give me your lastname: ')

print("My first name is {}, and my last name is {}".format(name, lastname))

# Introduce multiple integers separated by spaces
print('Give me number separated by spaces:')
A = list(map(int,input().split()))

# Introduce multiple floats separated by commas
B = list(map(float,input('Give me floats separated by commas:\n').split(',')))

# Introduce the date in format mm/dd/yyyy
day,month,year = map(int,input('Give me the date in format mm/dd/yyyy:\n').split('/'))