Python for Career Success in Data Science
Python Setup and Basics
Getting Your Tools Ready
Before you can write any Python code, you need two key things. First is Python itself, which is the engine that understands and runs your commands. Second is a special text editor, called an Integrated Development Environment (IDE), where you'll write your code.
Think of Python as a chef who only understands a specific language. The IDE is the kitchen where you write down your recipes for the chef to follow. For this course, we'll use Visual Studio Code, or VS Code, a popular and free IDE.
Once you have both Python and VS Code installed, you're ready to start. The most important thing to remember is that computers are very literal. They follow your instructions exactly, one line at a time, from top to bottom. They don't guess what you mean.
This is why is so important. Syntax is the set of grammar rules for a programming language. If you misspell a command or forget a punctuation mark, the computer won't understand, and your code won't work. It’s like forgetting a full stop in a sentence, but with more immediate consequences.
Your First Words
Let's write our first instruction. In programming, it's a tradition to make your first programme print the phrase "Hello, World!" to the screen. In Python, this is incredibly simple. We use a built-in command called print().
print("Hello, World!")
When you run this line of code, the text Hello, World! will appear in your output window. The print() function simply tells the computer to display whatever is inside the parentheses. The quotation marks tell Python that this is a piece of text.
You can also leave notes for yourself or other programmers in your code. These are called comments, and the computer ignores them completely. In Python, you start a comment with the hash symbol (#).
# This is a comment. The computer will not run this line.
print("This line will run.") # You can also put comments here.
Comments are useful for explaining what a tricky part of your code does. Use them to make your code easier to understand later.
Different Kinds of Data
In programming, we work with different types of information, or data. Think of them like different containers in a kitchen. You use a jar for flour, a bottle for water, and a box for teabags. You wouldn't store water in a teabag box. Python is just as specific about its data types.
For now, we'll look at three basic types.
Integer
noun
A whole number, without any fractional part. It can be positive, negative, or zero.
Float
noun
A number that has a decimal point. The name comes from how these numbers are stored in a computer's memory, using a "floating point" representation.
String
noun
A sequence of characters, such as letters, numbers, or symbols, enclosed in quotation marks. Essentially, it's just text.
You can use the print() function with any of these data types.
print(100) # Prints an integer
print(42.5) # Prints a float
print("Python is fun!") # Prints a string
Python can also do maths. You can use standard arithmetic operators directly in your code. Python follows the standard order of operations, sometimes remembered by the acronym (Brackets, Orders, Division, Multiplication, Addition, Subtraction).
| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 5 - 3 | 2 |
* | Multiplication | 5 * 3 | 15 |
/ | Division | 6 / 3 | 2.0 |
Notice that division (
/) with two integers can result in a float. For example,5 / 2gives2.5.
Now, let's test your understanding of these basic concepts.
In the analogy provided, what is the role of an Integrated Development Environment (IDE) like VS Code?
Why is syntax important in programming?
Great work taking your first steps. You've set up your environment, written your first code, and learned about the fundamental data types that are the building blocks of every Python programme.
