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

Speaker 1Speaker 2

Python Variables Basics

3:55
0:00-3:55
  1. Anna

    Alright Michael, let's dive into this Python tutorial. The video starts by explaining that Python is one of the most popular programming languages, used at Google and many universities, and it's great for beginners because the syntax is fairly simple.

  2. Michael

    Exactly. And it's used for a ton of stuff – backend web code, data analysis, scientific research. So learning it opens a lot of doors.

  3. Anna

    Right. The first practical step is installing Python. But instead of installing Python directly, the tutorial recommends using Anaconda, a package manager that bundles Python with Jupyter Notebook, which is what we'll use throughout the series.

  4. Michael

    So you go to anaconda.org, download the installer for your OS, make sure you get the Python 3 version, and run it. That gives you both Python and Jupyter.

  5. Anna

    Once Anaconda is installed, you launch Jupyter Notebook through the Anaconda Navigator. It pops up a command-line server and a browser window – that browser is your interface for writing and running code.

  6. Michael

    And one thing to remember: don't close that command-line window, or Jupyter will stop working. Now, to create your first notebook, you create a folder, open it in the Jupyter interface, and click 'New' then 'Python 3'. You can rename the notebook from 'Untitled' to something like 'what are variables'.

  7. Anna

    Each notebook contains cells. You type code in a cell and run it with the play button. The classic first program: print('Hello World') – and you see the string printed below.

  8. Michael

    And strings can be in single or double quotes. You can also print numbers directly, like print(3). If you have multiple lines in one cell, they execute one after another.

  9. Anna

    Now for the main topic: variables. In Python, a variable is like a name tag that refers to a value. When you write 'a = 1', you're saying the name 'a' refers to the integer 1.

  10. Michael

    That's different from languages where you think of a variable as a box. In Python, it's a reference. So 'b = 2' means b refers to 2. You can print the value with print(b) – no quotes around b because it's a variable name.

  11. Anna

    And variables can refer to strings too, like 'c = 'hello there'. Then print(c) shows 'hello there'. Multiple variables can refer to the same value: if d = 2, then b and d both refer to 2.

  12. Michael

    You can reassign variables. Start with b = 2, then b = 1 – now b refers to 1. You can even reassign a variable that used to hold a number to a string later. And if you try to print a variable that doesn't exist, like 'e', you get a NameError.

  13. Anna

    Also, you can assign one variable to another: f = a means f now refers to the value that a refers to at that moment. If a later changes to 2, f still stays at 1 – because f referred to the value, not the variable a itself.

  14. Michael

    Now the tutorial ends with a classic practice problem: swapping the values of two variables, v1 and v2. The naive approach v1 = v2; v2 = v1 doesn't work – after v1 = v2, both point to the same value, so v2 = v1 just sets both to the second string.

  15. Anna

    Right. The correct solution uses a temporary variable. Let temp refer to v1's value. Then set v1 to v2. Then set v2 to temp. Now v1 holds the second string and v2 holds the first. It's a simple but important pattern.

  16. Michael

    And you can test it in a new notebook. Call it 'swapping two variables'. Set v1 = 'first string', v2 = 'second string', then do the temp assignment and print both – it works perfectly.

  17. Anna

    So to recap: Python basics, Jupyter setup, the print function, variables as name tags, and the variable swap trick. Great foundations for absolute beginners.

  18. Michael

    Absolutely. And the video mentions you can download the files from cs.dojo. Also, if you want to keep up with more tutorials, subscribe to the newsletter. Ready for the next video?

  19. Anna

    Let's do it. See you in the next one.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent