Lesson 1 : Introduction To Python (Variables,strings,numbers, Comments) Flashcards

(57 cards)

1
Q

What type of language is Python?

A

Interpreted(executes the code line-by-line), high-level(because keywords are english-friendly), object-oriented, dynamically typed(interactive).

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

What does IDE stand for? And what is it ?

A

Integrated Development Environment.
It is a software that helps you create , edit and debug programs.

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

Name three examples of IDEs for Python.

A
  • IDLE
  • PyCharm
  • VS Code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does compiling mean in programming?

A

Translating the entire program into machine code before execution

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

How does Python execute code? And how is it called ?

A

Line by line. It is called interpreting.

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

What are the two modes in which Python can run?

A
  • Interactive mode
  • Script mode
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is IDLE in Python?

A

Python’s built-in lightweight IDE, good for beginners

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

What is PyCharm known for?

A

A powerful professional IDE for larger projects

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

What are identifiers in Python?

A

Names for variables, functions, or classes

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

What must identifiers in Python begin with?

A

A letter or underscore

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

What characters can identifiers contain?

A
  • Letters
  • Digits
  • Underscores
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Are identifiers in Python case-sensitive?

A

Yes

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

What are reserved words in Python?

A

Keywords with special meaning that cannot be used as identifiers

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

Give three examples of reserved words in Python.

A
  • if
  • for
  • while
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does Python define blocks of code?

A

Using indentation

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

What is the conventional number of spaces for indentation in Python?

A

4 spaces

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

What can cause errors related to indentation in Python?

A

Mixing tabs and spaces

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

How can multi-line statements be written in Python?

A
  • Using a backslash \
  • Enclosing expressions in parentheses (), square brackets [], or curly braces {}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What types of quotes can strings in Python use?

A
  • Single quotes ‘…’
  • Double quotes “…”
  • Triple quotes ‘'’…’’’ or “"”…”””
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How are comments written in Python?

A
  • Single-line comments using #
  • Multi-line comments using triple quotes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does Python’s clear syntax contribute to its ease of use?

A

Its English-like syntax and lack of compilation steps

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

Why is Python considered a high-level language?

A

It abstracts away complex low-level details

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

What is a code?

A

A set of instructions written in a programming language that tells the computer what to do.

24
Q

What is a code editor?

A

A software tool used to write and edit code, often providing features like syntax highlighting and auto-completion.

25
What is syntax highlighting?
A feature in code editors and IDEs that displays code in different colors or styles to distinguish elements.
26
What elements does syntax highlighting help to distinguish?
* Keywords * Variables * Strings * Comments
27
What is a traceback in Python?
A traceback is a record of where the interpreter ran into trouble when trying to execute your code. The output at reports that an error occurs in line x of the file, then the interpreter shows the line to help us spot the error quickly and tells us what kind of error it found .
28
What is a method?
A method is an action that Python can perform on a piece of data.
29
How is a method expressed?
Like this : name.title() The dot (.) after name in name.title() tells Python to make the title() method act on the variable name. Every method is followed by a set of parentheses, because methods often need additional information to do their work. That information is provided inside the parentheses.
30
Fill in the blank: A code editor often provides helpful features like _______.
[syntax highlighting and auto-completion]
31
What are the rules to adhere to when using variables in python ?
1- Variable names can contain only letters, numbers, and underscores. They can start with a letter or an underscore, but not with a number.For instance, you can call a variable message_1 but not 1_message. 2- Spaces are not allowed in variable names, but underscores can be used to separate words in variable names. For example, greeting_message works, but greeting message will cause errors. 3- Avoid using Python keywords and function names as variable names; that is, do not use words that Python has reserved for a particular programmatic purpose, such as the word print. • Variable names should be short but descriptive. For example, name is better than n, student_name is better than s_n, and name_length is better than length_of_persons_name. • Be careful when using the lowercase letter l and the uppercase letter O because they could be confused with the numbers 1 and 0.
31
What is a string ?
It is a type of data. A string is simply a series of characters. Anything inside quotes is considered a string in Python, and you can use single or double quotes around your strings like this: "This is a string." 'This is also a string.'
32
What are ways of changing cases in a string ?
Use can change strings cases by using methods. .title() : displays each word in titlecase, where each word begins with a capital letter. This is useful because you’ll often want to think of a name as a piece of information .upper() : displays each word in upper case. .lower() : displays each word in lower case .The lower() method is particularly useful for storing data. Many times you won’t want to trust the capitalization that your users provide, so you’ll convert strings to lowercase before storing them.
33
What is concatenation ?
It is a method of combining strings with the “+” symbol.
34
What are whitespaces in python and how to use them ?
In programming, whitespace refers to any nonprinting character, such as spaces, tabs, and end-of-line symbols. You can use whitespace to organize your output so it’s easier for users to read. To add a tab to your text, use the character combination \t as shown at u: >>> print("Python") Python >>> print("\tPython") Python To add a newline in a string, use the character combination \n: >>> print("Languages:\nPython\nC\nJavaScript") Languages: Python C JavaScript You can also combine tabs and newlines in a single string. The string "\n\t" tells Python to move to a new line, and start the next line with a tab. The following example shows how you can use a one-line string to generate four lines of output: >>> print("Languages:\n\tPython\n\tC\n\tJavaScript") Languages: Python C JavaScript
35
What can i do to ensure that there is no whitespace at left / right or both of a string ?
Use the rstrip() method to strip whitespace from the right. Use the lstrip() method to strip whitespace from the left. Use the strip() method to strip whitespace from both sides.
36
What is a syntax error ?
A syntax error occurs when Python doesn’t recognize a section of your program as valid Python code. For example, if you use an apostrophe within single quotes, you’ll produce an error. This happens because Python interprets everything between the first single quote and the apostrophe as a string. It then tries to interpret the rest of the text as Python code, which causes errors.
37
How can you manage integers in python ?
+ : Addition - : substraction * : Multiplication / : division ** : Exponents
38
What is a float ?
It is a number is a decimal point.
39
What is a type error ?
It’s when Python can’t recognize the kind of information you’re using. For example when Python sees at that you’re using a variable that has an integer value (int), but it’s not sure how to interpret that value : age = 23 message = "Happy " + age + "rd Birthday!" print(message).
40
How to turn a number into a string ?
Use the str() function. age = 23 message = "Happy " + str(age) + "rd Birthday!" print(message) Happy 23rd Birthday!
41
What is a variable ?
A variable in Python is a symbolic name that refers to a value stored in memory. It is essentially a placeholder or reference that allows you to store, access, and manipulate data within your program.
42
Give some python features
• Portable: It works on different operating systems like Windows, macOS, and Linux. You can write Python code on one system and run it on another without much hassle. • Extendable: Python is extendable because you can write parts of your program in other languages like C or C++ for performance, and then use those parts in Python. • Databases: Python can interact with databases like MySQL, PostgreSQL, or SQLite. You can use Python to store, retrieve, and manipulate data in these databases, making it great for backend development. • GUI Programming: Python has libraries (like Tkinter or PyQt) that allow you to create Graphical User Interfaces (GUIs). This lets you build desktop applications with windows, buttons, text fields, etc., without needing a web browser. • Scalable: Python is scalable because it can handle small scripts to large, complex systems. You can start with a simple program and, as your needs grow, extend it into a more sophisticated system without changing much of the original code.
43
What are the different python data types ?
- Numbers (int,float,complex) - Bool (True,False) - Sequence (String, list , tuple) - Mapping (Dictionnary) - Sets (set,frozenset)
44
Give examples of numbers :
Int : 1 Float : 1.0 Complex : i+2
45
Give examples of bool.
1==1 True 1==0 False
46
Give examples of sequences:
String = ‘ Omar’ List = [‘a,’b’,’c’] Tuple=(‘a’,’b’,’c’)
47
Give example of a mapping ?
Dictionary={‘’:’’,’’:’’}
48
Give python assignment operators.
= : assignment symbol +=: c+=a is equivalent to c=c+a -=: c-=a is equivalent to c=c-a *=: c*=a is equivalent to c=c*a /=: c/=a is equivalent to c=c/a %= c%=a is equivalent to c=c%a **= c**=a is equivalent to c=c**a //= c//=a is equivalent to c=c//a
49
Give bitwise operators.
a=10 and b=20 & : Binary and operator copies a bit to the result if it exists in both operands. | : Binary or operator copies a bit to the result if it exists in either operands. ^ : Binary XOR operator copies a bit to the result if it exists in one operand but not both. ~ : Binary ones complement operator is unary and has the effect of flipping bits << : Binary left shift operator. The left operands value is moved left by the number of bits specified by the right operand. >> : Binary right shift operator. The left operands value is moved right by the number of bits specified by the right operand.
50
Give some comparison operators.
> greater than < less than >= greater than and equal to <= less than and equal to == equal to != not equal to
51
Give some arithmetic operators.
+ addition - substraction * multiplication / division % modulus (divides left operand by right operant and returns remainder) ** exponent // floor division (The division of operands where the result is teh quotient in which the digits after the decimal point to are removed)
52
Give one advantage of python.
Easy to read , easy to learn , simple syntax.
53
What is interactive mode ?
Typing and running code directly in the python shell.
54
What are python logical operators ?
and : if both operand are true (not zero)then the condition is true or : if any operand is not zero then the condition is true not:Reveses logical state.
55
What are membership operators ?
In : evaluates to true if it finds a variable in the specified sequence and false if otherwise Not it : evaluates true if it does not find and false if otherwise.
56
How to get the reversal of two-digit number ?
Num=int(input(“2-digits number”)) Tens=num%10 Ones=num//10 Reversed = tens * 10 + ones print(reversed)