Made with ScholarlyMake flashcards like these from your own notes
Question:How does Python determine the data type of a variable?
Answer:Automatically inferred from assigned value.
Question:What does type() function return in Python?
Answer:The class type of the variable.
Question:When does a variable get created in Python?
Answer:When a value is first assigned to it.
Question:What type of language is Python regarding data types?
Answer:Dynamically typed.
Question:What is the default sort order of list elements in Python?
Answer:Ascending order.
Question:Which parameter in sort() reverses list order?
Answer:reverse=True.
Question:What keyword is used to define a function in Python?
Answer:def.
Question:How do you make a function return a value?
Answer:Using the return statement.
Question:How can you pass arbitrary arguments to a Python function?
Answer:Using *args for positional args.
Question:How can functions accept arbitrary keyword arguments?
Answer:Using **kwargs.
Question:What is a lambda function?
Answer:A small anonymous one-line function.
Question:What is the syntax for a lambda function?
Answer:lambda args : expression.
Question:What data structure stores multiple items with index positions?
Answer:List.
Question:How are list items accessed?
Answer:Using their index starting from 0.
Question:What are sets used for in Python?
Answer:Storing unique, unordered items.
Question:How are dictionaries structured in Python?
Answer:Key:value pairs.
Question:Are dictionary items ordered?
Answer:In Python 3.7+, yes.
Question:What keywords are used in Python for conditional statements?
Answer:if, elif, else.
Question:How does a while loop operate?
Answer:Executes as long as condition is True.
Question:What does break do inside a loop?
Answer:Stops the loop immediately.
Question:What is a class in Python?
Answer:A blueprint for creating objects.
Question:Which method initializes a class instance?
Answer:init().
Question:What are Python's built-in math functions for getting min and max?
Answer:min() and max().
Question:What does the abs() function return?
Answer:The absolute value.
Question:How does the pow() function work?
Answer:Calculates x raised to power y.
Question:What are try-except blocks used for?
Answer:Handling exceptions.
Question:Which block executes if no exception occurs in try-except?
Answer:else.
Question:What does list comprehension do?
Answer:Creates a list from an existing list more concisely.
Question:What does the map() function do?
Answer:Applies a function to each iterable item.
Question:How do you convert a variable’s type explicitly?
Answer:Using casting functions like int(), str(), etc.
Question:Are tuples mutable or immutable?
Answer:Immutable.
Question:How do you create a tuple?
Answer:Using parentheses ().
Question:What is tuple unpacking?
Answer:Assigning tuple elements to variables individually.
Question:What does zip() do?
Answer:Combines iterables into tuples pairing elements.
Question:What happens if zip() inputs have different lengths?
Answer:Length of shortest iterable.
Question:What does enumerate() provide when used in a loop?
Answer:Index and value of iterable elements.
Question:Are strings mutable in Python?
Answer:No, they are immutable.
Question:Can sets contain duplicate values?
Answer:No, sets only store unique elements.