Untitled Deck Flashcards

1
Q

What is Python?

A

A powerful, high-level programming language known for its readability and versatility

Python is an interpreted language, meaning code is executed line by line without needing to be compiled first.

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

What are the two primary modes of operation in Python?

A
  • Interactive Mode
  • Script Mode

Interactive Mode allows direct interaction with the Python interpreter, while Script Mode involves writing code in a file and executing it all at once.

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

List some applications of Python.

A
  • GUI Apps
  • Web Apps
  • Games
  • DBMS Apps
  • Scripting

Python is widely used for developing various types of applications.

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

What is a limitation of Python regarding speed?

A

Considered slower compared to compiled languages like C++

This can impact performance in compute-intensive applications.

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

What are tokens in Python?

A

The smallest unit of a programming language, also known as a lexical unit

Tokens are the building blocks of Python.

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

Name the types of tokens in Python.

A
  • Keywords
  • Identifiers
  • Literals
  • Operators
  • Punctuators

Each type of token serves a specific purpose in Python code.

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

What are keywords in Python?

A

Reserved words with specific meanings that cannot be used as identifiers

Keywords provide instructions to the interpreter.

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

Provide examples of Python keywords.

A
  • if
  • else
  • for
  • while
  • def
  • class
  • import
  • return
  • try
  • except
  • finally
  • with
  • yield
  • True
  • False
  • None
  • and
  • or
  • not
  • is
  • in
  • global
  • nonlocal
  • pass
  • break
  • continue
  • lambda
  • del
  • raise
  • assert
  • async
  • await

These keywords are fundamental to Python’s syntax and functionality.

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

What are identifiers in Python?

A

Names given to different parts of a program, such as variables, objects, classes, and functions

Identifiers must follow specific rules.

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

What are the rules for naming identifiers in Python?

A
  • Must begin with a letter or an underscore
  • Can include letters, numbers, and underscores
  • Case-sensitive
  • No limit on length
  • Cannot use keywords
  • Only underscores allowed for special symbols

These rules help maintain clarity and avoid conflicts in the code.

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

What are literals in Python?

A

Constant values that are directly embedded in the code

Literals can be of various types, including strings, numbers, and booleans.

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

List the types of literals in Python.

A
  • String Literals
  • Numeric Literals
  • Boolean Literals
  • Special Literal None
  • Literal Collections

Each type serves a unique purpose in representing data.

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

What are arithmetic operators in Python?

A

Operators that perform mathematical operations

These include addition, subtraction, multiplication, and division.

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

What is the purpose of operators in Python?

A

Symbols that perform specific actions on operands

Operators are essential for manipulating data and performing calculations.

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

What are punctuators in Python?

A

Symbols used to structure and separate parts of the code

They ensure proper syntax and meaning in the code.

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

What is a data type?

A

Defines the kind of information a variable can hold

Data types help in managing the data and operations performed on it.

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

List the core data types in Python.

A
  • Integer
  • Floating Point
  • Complex
  • String
  • List
  • Tuple
  • Dictionary

Each data type serves a specific role in data handling and storage.

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

What is Type Casting in Python?

A

Process of converting one data type to another

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

What are the two main types of type conversion in Python?

A

Implicit Type Conversion and Explicit Type Conversion

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

What is Implicit Type Conversion?

A

Automatic conversion by Python

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

What is Explicit Type Conversion?

A

Manual conversion by programmer

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

What does the int() function do?

A

Convert to integer

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

What does the float() function do?

A

Convert to floating-point number

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

What does the complex() function do?

A

Convert to complex number

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

What does the str() function do?

A

Convert to string

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

What does the bool() function do?

A

Convert to boolean

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

Provide an example of explicit type conversion.

A

a = “4”
b = int(a) # Explicit conversion from string to integer

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

What does the input() function return?

A

Always returns a string

Requires type casting for numerical operations

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

What is an empty statement in Python?

A

Uses pass keyword as a placeholder when no action is required

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

What is a simple statement?

A

Single line of code

Example: name = input(“Enter your Name”)

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

What is a compound statement?

A

Multiple statements grouped together, identified by a header line ending with a colon and an indented body

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

What are the types of control flow in Python?

A

Sequential, Selective, and Iterative

33
Q

What is the syntax of an if statement?

A

if condition: # statements to execute

34
Q

What is the syntax of an if-else statement?

A

if condition: # statements if true
else: # statements if false

35
Q

What is a nested if-else?

A

Multiple levels of conditional checking for complex decision-making scenarios

36
Q

What are the components of a loop?

A

Start, Step, and Stop

37
Q

What are the types of loops in Python?

A

for loop and while loop

38
Q

What does the range() function do?

A

Creates a sequence of numbers

Syntax: range(start, stop, step)

39
Q

What is an example of the range() function?

A

range(0, 5) → [0, 1, 2, 3, 4]

40
Q

What is another example of the range() function?

A

range(0, 10, 2) → [0, 2, 4, 6, 8]

41
Q

What does the break statement do?

A

Exits loop immediately, useful for early termination

42
Q

What does the continue statement do?

A

Skips current iteration and moves to next iteration

43
Q

What does the in operator do?

A

Checks if item exists in sequence, returns True or False

44
Q

What does the not in operator do?

A

Checks if item does not exist in sequence, returns opposite of in

45
Q

How can strings be created in Python?

A

Direct Assignment or User Input

Example: name = “Python” or name = input(“Enter name: “)

46
Q

What are the key takeaways about Python?

A

Python is flexible with type conversion, conditional and loop structures provide powerful control flow, understanding input handling is crucial, and membership operators simplify sequence checking.

47
Q

What is string traversal?

A

The process of accessing each character in a string, one by one, for display or other purposes.

Example: Printing a string in reverse order.

48
Q

What are the two string operators in Python?

A
    • (Concatenation)
    • (Replication)

+ joins two strings together, while * repeats a string a specified number of times.

49
Q

What does the + operator do when used with strings?

A

Joins two strings together.

Example: ‘tea’ + ‘pot’ results in ‘teapot’.

50
Q

What does the * operator do when used with strings?

A

Repeats a string a specified number of times.

Example: 5 * ‘@’ results in ‘@@@@@’.

51
Q

What is string slicing?

A

A technique for extracting a portion of a string.

Syntax: word[start:stop]

52
Q

How are indices assigned in a string?

A

Each character has an index starting from 0 for the first character and increasing by 1 for each subsequent character.

53
Q

What is the reverse index in strings?

A

Starts from -1 for the last character and decreases by 1 for each preceding character.

54
Q

What does the capitalize() function do?

A

Converts the first character of a string to uppercase.

55
Q

What does the find() function return?

A

Returns the lowest index of a substring within a string.

56
Q

What does the index() function return?

A

Returns the index of a substring within a string.

57
Q

What does the isalnum() function check?

A

Checks if all characters in a string are alphanumeric (letters or numbers).

58
Q

What does the isalpha() function check?

A

Checks if all characters in a string are alphabetical.

59
Q

What does the isdigit() function check?

A

Checks if all characters in a string are digits.

60
Q

What does the islower() function check?

A

Checks if all alphabetical characters in a string are lowercase.

61
Q

What does the isupper() function check?

A

Checks if all alphabetical characters in a string are uppercase.

62
Q

What does the join() function do?

A

Concatenates a sequence of strings into a single string, using a specified separator.

63
Q

What does the lower() function do?

A

Converts all characters in a string to lowercase.

64
Q

What does the upper() function do?

A

Converts all characters in a string to uppercase.

65
Q

What does the len() function return?

A

Returns the length of a string (number of characters).

66
Q

What does the ord() function return?

A

Returns the Unicode code point for a Unicode character.

67
Q

What does the reversed() function return?

A

Returns a reversed iterator of a sequence.

68
Q

What is the definition of a list in Python?

A

A standard data type that can store a sequence of values of any kind.

69
Q

How are lists represented in Python?

A

Lists are enclosed in square brackets [ ].

70
Q

What is meant by mutability in lists?

A

Lists are mutable data types, meaning their elements can be changed after creation.

71
Q

What is the syntax for accessing an element in a list?

A

L[i] where i is the index of the element.

72
Q

What does the + operator do when used with lists?

A

Concatenates two lists, adding the second list at the end of the first list.

73
Q

What does the * operator do when used with lists?

A

Repeats a list a specified number of times.

74
Q

What is the difference between strings and lists regarding mutability?

A

Strings are immutable; lists are mutable.

75
Q

What is list traversal?

A

Accessing and processing each element of a list.

76
Q

What is the syntax for list slicing?

A

seq = list[start:stop] where start is inclusive and stop is exclusive.

77
Q

What happens when you modify a list using slicing?

A

You can replace elements of the list at specified indices.

78
Q

Fill in the blank: The function _______ is used to create an empty list.