Python Fundamentals Quiz
20 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following accurately describes Python's nature as a programming language?

  • It is a low-level programming language.
  • It is an open-source object-oriented programming language. (correct)
  • It is primarily used for system programming.
  • It requires manual memory management.
  • Which of the following is NOT a type of token in Python?

  • Operator
  • Keyword
  • Punctuator
  • Variable (correct)
  • What is a primary benefit of Python being an interpreted language?

  • It generally has faster execution times than compiled languages.
  • It can perform direct compilation into machine code.
  • It allows for immediate execution of code without separate compilation. (correct)
  • It prevents cross-platform compatibility.
  • Which of the following Python interpreters allows for a graphical user interface?

    <p>Python IDLE</p> Signup and view all the answers

    How many keywords are there in Python as mentioned in the fundamentals?

    <p>33</p> Signup and view all the answers

    Which of the following data types is considered a primitive data type in Python?

    <p>String</p> Signup and view all the answers

    What will be the output of the following code: print(1, 2, 3, sep='-')?

    <p>1-2-3</p> Signup and view all the answers

    In Python, what type of data does the variable w=1 represent?

    <p>Integer</p> Signup and view all the answers

    What is the default ending character printed by the print() function if no end argument is specified?

    <p>Newline</p> Signup and view all the answers

    Which of the following correctly defines a complex number in Python?

    <p>1 + 2j</p> Signup and view all the answers

    Which of the following statements about Python strings is true?

    <p>Strings can contain both single and double quotes interchangeably.</p> Signup and view all the answers

    In Python, which of the following data types is considered immutable?

    <p>Tuple</p> Signup and view all the answers

    What is the purpose of the 'real' and 'imag' attributes in Python?

    <p>To access the real and imaginary parts of a complex number.</p> Signup and view all the answers

    Which of the following operators is NOT considered a basic arithmetic operator in Python?

    <p>Concatenation (&amp;)</p> Signup and view all the answers

    What will the value of variable x be after the following code is executed? x = 5; x = 'hello'; x = 10.5;

    <p>10.5</p> Signup and view all the answers

    Identify the correct example of a floating point number in Python.

    <p>1.0</p> Signup and view all the answers

    Which of the following is NOT a valid variable name in Python?

    <p>1stVariable</p> Signup and view all the answers

    What is the output of the following code? p, q, r = 5, 10, 7; q, r, p = p + 1, q + 2, r - 1; print(p, q, r)

    <p>6 12 5</p> Signup and view all the answers

    When Python evaluates an expression with multiple variables on the left-hand side, how is the assignment handled?

    <p>The LHS variables are assigned values from the RHS in the same order they appear.</p> Signup and view all the answers

    What will the value of variable y be after executing: y = int(2.8); y = int('5.9');

    <p>5</p> Signup and view all the answers

    Study Notes

    Introduction to Python

    • Python is a general-purpose, high-level, object-oriented programming language
    • Developed by Guido van Rossum in the late 1980s at the National Research Institute for Mathematics and Computer Science in the Netherlands
    • Derived from languages like ABC, Modula-3, Smalltalk, and Algol-68
    • An open-source scripting language
    • Case-sensitive language (uppercase and lowercase letters matter)
    • An official language at Google

    Characteristics of Python

    • Interpreted: source code compiled to bytecode (.pyc file) then interpreted by the interpreter
    • Interactive
    • Object-oriented
    • Easy and simple
    • Portable
    • Scalable (supports large programs)
    • Integrated
    • Expressive language

    Python Interpreters

    • Various interpreters exist, including PyCharm, Python IDLE, The Python Bundle, and pyGUI
    • Other interpreters like Sublime Text are available.

    Using Python Interpreters

    • Interactive Mode: Allows interaction with Python directly
    • Script Mode: Running Python code from a file

    Python Character Set

    • Letters (A-Z, a-z)
    • Digits (0-9)
    • Special Symbols (! @ # $ % ^ & * ( ) _ + - = { } [ ] : ; " ' , < . > / ? )
    • Whitespace (spaces, tabs, newline)

    Tokens

    • Smallest individual unit in a program.
    • Python has five token types: keywords, identifiers, literals, operators, punctuators

    Keywords

    • Reserved words in Python.
    • There are 33 keywords in total (e.g., False, class, finally, is, return, break, None, continue, for, lambda, try, except, True, def, from, nonlocal, while, in, and, del, global, not, with, raise, as, elif, if, or, yield, assert, else, import, pass).

    Identifiers

    • Names given by the user for variables, classes, function names, etc.
    • Must start with a letter or underscore, followed by letters, digits, or underscores
    • Keywords cannot be used as identifiers.
    • Special symbols are not allowed (e.g. ! @ # $ % etc.)
    • Commas and spaces are not allowed inside identifiers

    Literals

    • Constant values in a program
    • Four types exist: numeric (int, float, complex), string, boolean, special (None)

    Numeric Literals

    • Immutable (cannot be changed)
    • Examples: 5, 6.7, 6+9j

    String Literals

    • Encoded text within quotes ("string" or 'string')
    • Supports escape sequences (e.g., ', ", \t, \n)

    Boolean Literals

    • Two possible values: True or False

    Special Literals

    • None: Represents the absence of a value or no object, often used as an end marker for lists.

    Literal Collections

    • Collections like tuples, lists, and dictionaries are used in Python.

    Basic Terms in Python Programs

    • Blocks & Indentation: Python uses indentation to define code blocks (no braces)
    • Statements: Instructions or expressions on a single line.
    • Expressions: Combinations of symbols and values producing results.
    • Comments: Ignored by the interpreter; used for explanations (# followed by comment).

    Single-Line Comments

    • Start with #

    Multi-Line Comments

    • Enclosed in triple quotes (''' ... ''')

    Variable/Label

    • Python variables are named locations referring to values.
    • Variables are created by assigning values
    • Dynamically typed: no need to specify beforehand.

    Value and RValue

    • Left-hand side (Lvalue) of an expression, where a value will be assigned
    • Right-hand side (Rvalue) of an expression, where the value will be computed

    Data Types in Python

    • Primitive (Numbers, String)
    • Collection (List, Tuple, Set, Dictionary)
    • Integer, Float, Complex, String, Boolean and others

    Basic Operators

    • Arithmetic (+, -, *, /, //, %, **)
    • Relational/Comparison (>, <, ==, !=, >=, <=)
    • Logical (and, or, not)
    • Bitwise
    • Assignment (=, +=, -=, etc.)
    • Other (special, identity, membership)

    Conditional Statements (if-else, elif)

    • Control execution flow based on certain conditions (True or False)

    Loops (while, for, loop else)

    • Repeat statements until a condition is met
    • for is used to iterate over a sequence, while is used for conditions
    • loop else: runs when no break occurs

    Jump Statements (break, continue)

    • break: Exits a loop entirely
    • continue: Skips the current iteration, goes to the next

    Nested Loops

    • Loop inside another loop

    Modules

    • Bundles of functions for specific tasks (e.g., math, random)
    • import brings them into the current program

    Functions

    • Reusable blocks of code performing specific operations
    • def keyword marks function start.
    • Pass parameters with arguments.

    User-Defined Functions

    • Functions written by the programmer (not built into Python)

    Library Functions

    • Predefined functions (e.g., type(), len())

    Lambda Functions

    • Anonymous functions (defined without a name using lambda)

    Data Type Types (Mutable vs Immutable)

    • Mutable data can be changed in-place (e.g., lists)
    • Immutable data cannot be changed in-place (e.g., tuples)

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Introduction to Python PDF

    Description

    Test your knowledge on Python's fundamental concepts with this quiz. It covers topics such as data types, tokens, and the characteristics of Python as an interpreted language. See how well you understand the essentials of Python programming.

    More Like This

    Use Quizgecko on...
    Browser
    Browser