Untitled Deck Flashcards
(78 cards)
What is Python?
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.
What are the two primary modes of operation in Python?
- 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.
List some applications of Python.
- GUI Apps
- Web Apps
- Games
- DBMS Apps
- Scripting
Python is widely used for developing various types of applications.
What is a limitation of Python regarding speed?
Considered slower compared to compiled languages like C++
This can impact performance in compute-intensive applications.
What are tokens in Python?
The smallest unit of a programming language, also known as a lexical unit
Tokens are the building blocks of Python.
Name the types of tokens in Python.
- Keywords
- Identifiers
- Literals
- Operators
- Punctuators
Each type of token serves a specific purpose in Python code.
What are keywords in Python?
Reserved words with specific meanings that cannot be used as identifiers
Keywords provide instructions to the interpreter.
Provide examples of Python keywords.
- 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.
What are identifiers in Python?
Names given to different parts of a program, such as variables, objects, classes, and functions
Identifiers must follow specific rules.
What are the rules for naming identifiers in Python?
- 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.
What are literals in Python?
Constant values that are directly embedded in the code
Literals can be of various types, including strings, numbers, and booleans.
List the types of literals in Python.
- String Literals
- Numeric Literals
- Boolean Literals
- Special Literal None
- Literal Collections
Each type serves a unique purpose in representing data.
What are arithmetic operators in Python?
Operators that perform mathematical operations
These include addition, subtraction, multiplication, and division.
What is the purpose of operators in Python?
Symbols that perform specific actions on operands
Operators are essential for manipulating data and performing calculations.
What are punctuators in Python?
Symbols used to structure and separate parts of the code
They ensure proper syntax and meaning in the code.
What is a data type?
Defines the kind of information a variable can hold
Data types help in managing the data and operations performed on it.
List the core data types in Python.
- Integer
- Floating Point
- Complex
- String
- List
- Tuple
- Dictionary
Each data type serves a specific role in data handling and storage.
What is Type Casting in Python?
Process of converting one data type to another
What are the two main types of type conversion in Python?
Implicit Type Conversion and Explicit Type Conversion
What is Implicit Type Conversion?
Automatic conversion by Python
What is Explicit Type Conversion?
Manual conversion by programmer
What does the int() function do?
Convert to integer
What does the float() function do?
Convert to floating-point number
What does the complex() function do?
Convert to complex number