Exam (COMP10) (PHINMA)

Cards (40)

  • Who created Python and when was it first released?
    Guido van Rossum created Python, and it was first released in 1991.
  • What are the main characteristics of Python?
    Python is a high-level, interpreted programming language known for its readability and simplicity.
  • What is the latest version of Python as of August 2024?
    The latest version of Python as of August 2024 is Python 3.12.
  • What symbol is used to start a single-line comment in Python?
    The # symbol is used to start a single-line comment in Python.
  • Why are comments used in Python code?
    Comments are used to explain code and are ignored by the interpreter.
  • What are the built-in variable types in Python?
    • Integer (int): Whole numbers (e.g., x = 10)
    • Floating Point (float): Decimal numbers (e.g., y = 3.14)
    • String (str): Text (e.g., name = "John")
    • Boolean (bool): True or False (e.g., is_active = True)
    • List (list): Ordered collection of items (e.g., numbers = [1, 2, 3])
    • Dictionary (dict): Collection of key-value pairs (e.g., person = {"name": "John"})
  • What is a dictionary in Python?
    A dictionary is a collection of key-value pairs, enclosed in curly braces.
  • How do you convert a string to an integer in Python?
    You can convert a string to an integer using int(num_str)int(num\_str).
  • What are the rules for naming variables in Python?
    1. Names must start with a letter (a-z, A-Z) or an underscore.
    2. Names can be followed by letters, digits (0-9), or underscores.
    3. Names are case-sensitive.
    4. Avoid using Python reserved words (keywords) as variable names.
  • What are the applications and use cases of Python?
    • Scientific Computing and Research
    • Data Science and Machine Learning
    • Web Development
    • Automation and Scripting
    • Software Development
    • Networking
  • What is the purpose of an Integrated Development Environment (IDE)?

    • Helps you write, debug, and manage your code more efficiently.
    • Popular IDEs for Python include PyCharm and Visual Studio Code.
  • What is the purpose of indentation in Python?
    Indentation is used to define the structure of the code, particularly for blocks of code.
  • How are variables declared and initialized in Python?
    In Python, you create a variable by assigning it a value using the assignment operator =.
  • What are the different data types in Python?
    • Integer (int): Whole numbers (e.g., num = 42)
    • Float (float): Decimal numbers (e.g., pi = 3.14159)
    • String (str): Text (e.g., greeting = "Hello, World!")
    • Boolean (bool): Represents True or False (e.g., is_valid = False)
    • List (list): Ordered collection of items (e.g., fruits = ["apple", "banana", "cherry"])
    • Tuple (tuple): Ordered, immutable collection of items (e.g., coordinates = (10, 20))
  • What are the arithmetic operators in Python?
    • Addition: ` + `
    • Subtraction: ` - `
    • Multiplication: ` * `
    • Division: ` / `
    • Integer Division: ` // `
    • Modulus: ` % `
    • Exponentiation: ` ** `
  • What is the result of a=a =10,b= 10, b =3;a+ 3; a +b b in Python?

    1313
  • What is the result of a=a =10,b= 10, b =3;ab 3; a - b in Python?

    77
  • What is the result of a=a =10,b= 10, b =3;a 3; a *b b in Python?

    3030
  • What is the result of a=a =10,b= 10, b =3;a/b 3; a / b in Python?

    103\frac{10}{3}
  • What is the result of a=a =10,b= 10, b =3;a//b 3; a // b in Python?

    33
  • What is the result of a=a =10,b= 10, b =3;a 3; a % b in Python?

    11
  • What is the result of a=a =10,b= 10, b =3;a 3; a **b b in Python?

    10001000
  • What are the comparison operators in Python?
    • Equal to: ==
    • Not equal to: !=
    • Greater than: >
    • Less than: <
    • Greater than or equal to: >=
    • Less than or equal to: <=
  • What are the logical operators in Python?
    • And: and
    • Or: or
    • Not: not
  • What are conditional statements in Python?
    • Conditional statements allow you to execute code based on certain conditions.
  • What is a variable in programming?
    A variable is a symbolic name associated with a value, acting as a placeholder for data.
  • How are variables in Python typed?
    Variables in Python are dynamically typed, meaning you don't have to explicitly declare the type.
  • How do you declare and initialize a variable in Python?
    You declare and initialize a variable by assigning it a value using the assignment operator =.
  • What is the syntax for concatenating strings in Python?
    You can concatenate strings using the + operator.
  • What is the output of print("Hello"+full_name)print("Hello " + full\_name) if full_name=full\_name ="BroCode" "Bro Code"?

    HelloBroCodeHello Bro Code
  • What is the assignment operator in Python?
    The assignment operator in Python is =.
  • What is the significance of the assignment operator in Python?
    The assignment operator is used to assign a value to a variable.
  • What is the purpose of the print function in Python?
    The print function is used to output data to the console.
  • How does Python handle variable types?
    Python infers the variable type from the assigned value, so explicit declaration is not needed.
  • What is the difference between a list and a tuple in Python?
    A list is mutable (can be changed), while a tuple is immutable (cannot be changed).
  • What is the syntax for creating a list in Python?
    A list is created using square brackets, e.g., fruits=fruits =["apple","banana","cherry"] ["apple", "banana", "cherry"].
  • What is the syntax for creating a tuple in Python?
    A tuple is created using parentheses, e.g., coordinates=coordinates =(10,20) (10, 20).
  • What is the syntax for creating a set in Python?
    A set is created using curly braces, e.g., myset=my_set =1,2,3 {1, 2, 3}.
  • What is the purpose of a set in Python?
    A set is an unordered collection of unique items.
  • What is the purpose of control structures in Python?
    Control structures allow you to execute code based on certain conditions.