1. Home
  2. Explore
  3. Computer Science
  4. Python Variables Basics

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Python Variables Basics

  • 24Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Python Overview
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is Python and what are its common uses?

Tap to flipClick to flipspace

Python is a popular programming language used at companies like Google and universities. It is used for web backend code, data analysis, and scientific research.

Or swipe the card

24 cards

  1. What is Python and what are its common uses?

    Python is a popular programming language used at companies like Google and universities. It is used for web backend code, data analysis, and scientific research.

  2. What is an advantage of Python's syntax?

    Python has fairly simple syntax, making it easy to learn.

  3. What is the role of Anaconda in installing Python?

    Anaconda is a package manager that installs Python and Jupyter Notebook together, so you don't need to install them separately.

  4. What are the two components of Jupyter Notebook?

    The Jupyter Notebook server (command line interface) and the browser user interface (UI) connected to the server.

  5. Which Python version should you install via Anaconda for this course?

    Python 3 (the version with 3.something), not Python 2.

  6. How do you launch Jupyter Notebook after installing Anaconda?

    Open Anaconda Navigator and click 'Launch' under Jupyter Notebook.

  7. What is a 'cell' in Jupyter Notebook?

    A cell is a set of code. You can run the code in a cell using the run button, and the output appears below.

  8. What does the print function do in Python?

    It prints whatever is inside the parentheses to the output.

  9. How are strings enclosed in Python?

    Strings can be enclosed in either double quotes (") or single quotes (').

  10. What happens if you forget to close a parenthesis or quote when using print?

    You get an error.

  11. Can the print function output numbers without quotes?

    Yes, you can print numbers directly, e.g., print(3) outputs 3.

  12. How do you create a variable in Python?

    Use the assignment operator = : a = 1 assigns the value 1 to variable a.

  13. In Python, is a variable like a box containing a value or a name tag?

    A variable is more like a name tag that refers to a value, not a box.

  14. How do you see what value a variable refers to?

    Use print(variable_name) without quotes around the variable name.

  15. Can a variable refer to a string?

    Yes, variables can refer to strings as well as numbers.

  16. Can two or more variables refer to the same value?

    Yes, it is possible. For example, d = 2 and b = 2 both refer to the same integer 2.

  17. How do you reassign an existing variable to a different value?

    Use the assignment operator again: b = 1 after b = 2 makes b refer to 1.

  18. What happens if you try to print a variable that hasn't been defined?

    You get a NameError: the variable is not defined.

  19. If you write f = a, does f refer to the variable a or the value a refers to?

    f refers to the value that a refers to, not the variable a itself.

  20. After a = 1; f = a; a = 2, what value does f refer to?

    f still refers to 1.

  21. What is the naive way to swap two variables, and why does it fail?

    Naive: v1 = v2; v2 = v1. This fails because after the first line, both variables refer to the same value, so the second line makes v2 refer to that same value (not the original v1).

  22. What is the correct way to swap two variables using one temporary variable?

    temp = v1 v1 = v2 v2 = temp

  23. Can you swap variables using two temporary variables?

    Yes: temp1 = v1; temp2 = v2; v1 = temp2; v2 = temp1.

  24. Why is the single temporary variable swap pattern important to know?

    It is a very common pattern used by programmers for swapping values.

Card 1 of 24
Card 1 of 24

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent