Python

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Python

Print Function

Print(”Hello World”)
If you want to have double quotes inside the print function, you can use single quotes to
close the print string
Print(’hello “this” name’)

Input Function
Input(”prompt”) ⟹ Can use this in code now.

💡 If I put the input function inside the print function, the input function is run as it
is required for the print function to move forward.
So print(”Hi “ + INPUT(”What is your name”)) will first display What is your
name? and once the user inputs his name, it will take the name and execute
the print function.

len() - calculate the length of the string

Variables can be used to store a piece of data.


X = “whatever you want the variable to be”
If Python can’t find a particular variable it will give out a “Name Error”
\n = new variable

Python 1
Subscripting, you can disect Xth letter by [X-1](As we start from 0)

Data Types

String : A bunch of letters of numbers, that are together. To convert something into a
string, you can use the function str()
Integer: Non Decimal Number
Float: Including Decimal Number
Boolean: Yes or No

You can use the function type() to know the type

You can use variables inside a string by using “f” before starting the string.

example: f”sri {variable_name}”

You can use round(number, number of digits) to round a number.

Python 2

You might also like