Get 60% off lifetime access &
job ready curriculum guide

YOU WILL RECEIVE DISCOUNT CODE AND THE GUIDE INTO YOUR EMAIL AFTER SIGNING UP

    We don’t send spam. Unsubscribe anytime.

    Author

    “Your course helped me get my job as a software engineer at Charles Schwab. The course was easy to follow and covered all the material I'd need to nail a leetcode style interview. Thank you!”

    - Mohammed Khan
    Beginner’s Guide to Python: From Installation to Understanding Variables

    Beginner’s Guide to Python: From Installation to Understanding Variables

    August 13, 2024 by Imtiaz Ahmad

    Table of Contents

    Welcome to your journey into the world of Python programming! Whether you’re a complete beginner or just brushing up on the basics, this blog will walk you through some foundational concepts. In this Beginner’s Guide to Python: From Installation to Understanding Variables, we’ll start with installing Python, writing your first “Hello, World!” program, and exploring the essentials of variables and data types.

    1. Python Installation

    Before we dive into coding, let’s ensure you have Python installed on your computer. Python is easy to install and works on all major platforms.

    For Windows

    1. Go to the Python official website

    2. Download the latest version of Python.

    3. Run the installer. Make sure to check the box that says “Add Python to PATH” before clicking “Install Now.”

    For macOS

    1. Python 2 comes pre-installed on macOS, but you’ll need Python 3.

    2. Download the latest version from the Python official website

    3. Follow the instructions on the installer to complete the setup.

    For Linux

    1. Open your terminal.

    2. Use the following command to install Python:

    sudo apt-get install python3

    After installation, open your terminal (or command prompt on Windows), type python --version, and press Enter. If everything went well, you’ll see the version of Python you’ve installed.

    2. Your First Python Program: Hello World!

    Now that Python is installed, let’s write your first program. We’ll start with the classic “Hello, World!” example.

    Open a text editor or an IDE (Integrated Development Environment) like VSCode, PyCharm, or even the simple IDLE (Integrated Development and Learning Environment) that comes with Python.

    Type the following code:

    print("Hello, World!")

    Save the file with a .py extension, for example, hello.py and to run your program, open a terminal or command prompt, navigate to the directory where you saved the file, and type:

    python hello.py

    You should see the text Hello, World! printed on the screen. Congratulations! You’ve just written and executed your first Python program.

    3. Understanding Variables

    A variable is a container for storing data. Think of it as a label attached to a value, making it easier to reference that value later in your code. In Python, you don’t need to declare a variable with a specific type. You simply assign a value to a variable using the = sign.

    For example:

    greeting = "Hello, World!"
    age = 25
    is_student = True

    Here, greeting holds a string "Hello, World!", age holds an integer 25, and is_student holds a boolean True.

    4. Data Types in Python

    Python has several built-in data types that you’ll frequently use:

    • Strings: Used to store text. They are enclosed in quotes.
    name = "Alice"
    • Integers: Whole numbers, without a fractional component.
    age = 30
    • Float (Floating point numbers): Numbers with a fractional component.
    height = 5.9
    • Booleans: True or False values.
    is_student = False

    5. Working with Variables and Data Types

    Let’s put what we’ve learned into practice. Consider the following example:

    first_name = "Alice"
    last_name = "Johnson"
    age = 25
    full_name = first_name + " " + last_name
    
    print("Name:", full_name)
    print("Age:", age)

    This code defines three variables: first_name, last_name, and age. We then combine first_name and last_name using the + operator to create a full_name variable. The print() function is used to display the values.

    Here’s how Python handles different types of data:

    • String Concatenation: Combining two strings with the + operator.
    • Integer Operations: You can add, subtract, multiply, or divide integers.
    • Type Conversion: Sometimes you may need to convert one type to another. For example, converting an integer to a string:
    age = 25
    age_str = str(age)

    If you try to concatenate a string with an integer directly, you’ll get an error. But by converting the integer to a string first using str(), you can combine them:

    print("I am " + age_str + " years old.")

    Resources

     Conclusion

    And that’s it for this beginner’s guide! You’ve learned how to install Python, write a basic program, and use variables with different data types. Keep practicing these fundamentals as they are the building blocks of more complex programs. Happy coding!

    Subscribe

      We do not send spam. Unsubscribe anytime.
      Back to blog
      Self Improvement | Software Development
      Top 5 Self Improvement Hacks

      In this blog, I want to give you five Self Improvement hacks that will help you improve your life and make you into a better version of yourself. And these are hacks that have changed my life which I use every day. Hack 1 – Reflex Retraining We’ll start with the first one which is […]

      Imtiaz Ahmad
      Data Analytics | Personal Branding
      How to boost your LinkedIn Profile?

      In this blog, we will look into several tips that will help you increase your LinkedIn profile’s visibility and keep it professional. Importance of profile picture To begin, let’s understand why it’s so important to have a profile picture on your LinkedIn profile. If someone looks at your profile and sees your profile picture blank, […]

      Imtiaz Ahmad
      Software Development
      Too Old For Software Development

      So are you too old to get into software development? I can’t tell you the number of times I get asked this question. People are asking all the time. I’m 30 years old is it too late for me to get into software development? I mean come on! Age is not a limit If you’re […]

      Imtiaz Ahmad