Python Basics Flashcards

Learn python basics

1
Q

How to run program on Python?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can you define varibale?

A

Veriable is just a countainer to stor some value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How dou you call = operator in programming?

A

It’s an assigment operator. So basically you want to assign something to something.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to add comment in Python?

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What types of parameter in Function you can name?

A
  1. Positional - It’s a parameter that will be printed on by one in order it was passed in function.
  2. 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to use quots in string?

A

you can use \ for escaping ot just use “” and inside you can use single quotes ‘’.
print(“Hello World” 'friend')
print (‘Hello world “friend”’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is formated string in Python?

A

Formated string in python is the way to embed expression inside strings literals. Easely allowing us to use variables inside strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many way you know to use formated string?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What method for string data type i can use to remove white space on left and right ?

A

str.stip()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How i can capitalize string in python?

A

we can capitalize string with method str.capitalize()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How we can spilt string in Python?

A

We can use method str.spilt()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to converte str into int in python?

A

You can use function int()
int(x)
int(input(“Add a numerber here”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What data types you know in python?

A

Str - string
Int- Integer (number without decimal point)
Float - floating point valus(number with decimal)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to define function in Python?

A

We can use keyword def to define function in Python

def hello():
function body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can we add default value to function parameter in Python?

A

Yes, we can do so by using = operator to a pramater
def name(userName=”Martin”):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly