Logo/

Python Basics and Data Structures

Log in

Made with ScholarlyMake flashcards like these from your own notes

Python Basics and Data Structures

Questions and answers

38 cards
  1. Question:How does Python determine the data type of a variable?

    Answer:Automatically inferred from assigned value.

  2. Question:What does type() function return in Python?

    Answer:The class type of the variable.

  3. Question:When does a variable get created in Python?

    Answer:When a value is first assigned to it.

  4. Question:What type of language is Python regarding data types?

    Answer:Dynamically typed.

  5. Question:What is the default sort order of list elements in Python?

    Answer:Ascending order.

  6. Question:Which parameter in sort() reverses list order?

    Answer:reverse=True.

  7. Question:What keyword is used to define a function in Python?

    Answer:def.

  8. Question:How do you make a function return a value?

    Answer:Using the return statement.

  9. Question:How can you pass arbitrary arguments to a Python function?

    Answer:Using *args for positional args.

  10. Question:How can functions accept arbitrary keyword arguments?

    Answer:Using **kwargs.

  11. Question:What is a lambda function?

    Answer:A small anonymous one-line function.

  12. Question:What is the syntax for a lambda function?

    Answer:lambda args : expression.

  13. Question:What data structure stores multiple items with index positions?

    Answer:List.

  14. Question:How are list items accessed?

    Answer:Using their index starting from 0.

  15. Question:What are sets used for in Python?

    Answer:Storing unique, unordered items.

  16. Question:How are dictionaries structured in Python?

    Answer:Key:value pairs.

  17. Question:Are dictionary items ordered?

    Answer:In Python 3.7+, yes.

  18. Question:What keywords are used in Python for conditional statements?

    Answer:if, elif, else.

  19. Question:How does a while loop operate?

    Answer:Executes as long as condition is True.

  20. Question:What does break do inside a loop?

    Answer:Stops the loop immediately.

  21. Question:What is a class in Python?

    Answer:A blueprint for creating objects.

  22. Question:Which method initializes a class instance?

    Answer:init().

  23. Question:What are Python's built-in math functions for getting min and max?

    Answer:min() and max().

  24. Question:What does the abs() function return?

    Answer:The absolute value.

  25. Question:How does the pow() function work?

    Answer:Calculates x raised to power y.

  26. Question:What are try-except blocks used for?

    Answer:Handling exceptions.

  27. Question:Which block executes if no exception occurs in try-except?

    Answer:else.

  28. Question:What does list comprehension do?

    Answer:Creates a list from an existing list more concisely.

  29. Question:What does the map() function do?

    Answer:Applies a function to each iterable item.

  30. Question:How do you convert a variable’s type explicitly?

    Answer:Using casting functions like int(), str(), etc.

  31. Question:Are tuples mutable or immutable?

    Answer:Immutable.

  32. Question:How do you create a tuple?

    Answer:Using parentheses ().

  33. Question:What is tuple unpacking?

    Answer:Assigning tuple elements to variables individually.

  34. Question:What does zip() do?

    Answer:Combines iterables into tuples pairing elements.

  35. Question:What happens if zip() inputs have different lengths?

    Answer:Length of shortest iterable.

  36. Question:What does enumerate() provide when used in a loop?

    Answer:Index and value of iterable elements.

  37. Question:Are strings mutable in Python?

    Answer:No, they are immutable.

  38. Question:Can sets contain duplicate values?

    Answer:No, sets only store unique elements.