Python Basics Flashcards
Learn python basics
How to run program on Python?
You need python to be installed on your computer and run in terminal prompt: python + file name;
python hello.py. In this case interpretor (python itself) will read out programm top to bottom left to right and will translate it into mashine code 0 and 1.
How can you define varibale?
Veriable is just a countainer to stor some value.
How dou you call = operator in programming?
It’s an assigment operator. So basically you want to assign something to something.
How to add comment in Python?
#
What types of parameter in Function you can name?
- Positional - It’s a parameter that will be printed on by one in order it was passed in function.
- Named - Optional parameters that you can call by using it’s name.
print(“Hello world”, sep=” “)
Sep is a name parameter and “hello world” is positional.
How to use quots in string?
you can use \ for escaping ot just use “” and inside you can use single quotes ‘’.
print(“Hello World” 'friend')
print (‘Hello world “friend”’)
What is formated string in Python?
Formated string in python is the way to embed expression inside strings literals. Easely allowing us to use variables inside strings.
How many way you know to use formated string?
There is a 3 way.
1. f-strings
This is the most modern and recommended approach. It uses curly braces {} to embed variables or expressions directly within the string. You prefix the string with f.
name = “Martin”
print(f”hello, {name }”) => Hello Martin
2. str.format()
This method involves placing curly braces {} in the string and calling the .format() method to insert values.
name = “Alice”
age = 25
greeting = “Hello, my name is {} and I am {} years old.”.format(name, age)
print(greeting)=> Hello, my name is Alice and I am 25 years old.
3 Percent (%) Formatting
What method for string data type i can use to remove white space on left and right ?
str.stip()
How i can capitalize string in python?
we can capitalize string with method str.capitalize()
How we can spilt string in Python?
We can use method str.spilt()
How to converte str into int in python?
You can use function int()
int(x)
int(input(“Add a numerber here”))
What data types you know in python?
Str - string
Int- Integer (number without decimal point)
Float - floating point valus(number with decimal)
How to define function in Python?
We can use keyword def to define function in Python
def hello():
function body
Can we add default value to function parameter in Python?
Yes, we can do so by using = operator to a pramater
def name(userName=”Martin”):