My First Steps in Python: A Beginner’s Journey into Coding
Embarking on a coding journey can be both exhilarating and daunting, especially with so many resources at your fingertips. After exploring various options and gathering advice, I found that YouTube offers a great starting point for beginners like me. But of course, it’s just one of many valuable resources available to learn Python.
- Interactive learning platforms: Codeacademy, DataCamp, Codewars
- Online Courses: Coursera, edX
- Books: “Python Crash Course” by Eric Matthes
- Video tutorials: YouTube, Coursera
Additionally, there are a plethora of community forums, coding challenges, and hands-on projects to reinforce and apply your learning.
I started with the most simplistic line of coding possible in Python, with the print command.
print('Hello World!')
While this line of code doesn’t do much, it feels like a major step in advancing my basic knowledge of which parts do what. For example, the print function allows you to display whatever is encased between the parentheses into the terminal. In this instance would be the words print(‘Hello World!’). This simple command encapsulates much of what programming is about, giving instructions to the computer to perform a task.
After this, I decided to learn the basic functions of Python. This required me to delve deeper into the execution orders, datatypes, operations, variables and inputs.
Understanding Execution Order
print('Line 1')
print('Line 2')
print('line 3')
Simply put, this is the order in which each line of code is executed, from top to bottom. Understanding that if we have more than one line of code for this instance ‘Line 1’ ‘Line 2’ and ‘Line 3’, we always start from ‘Line 1’ executing each line subsequently as we go down.
Exploring Data Types
print('words') #strings
print(123) #integers/ints
print(2.5) #floating point value/ float
After some research, I discovered that there are 3 main basic datatypes in Python; strings, floating point values and integers. Strings are inherently considered text, enclosed in quotes, for example, print(‘words’). Integers and floating-point values are numeric data within the command with the key difference being that floating-point values include decimals, for example, print(2.5) and the integer does not.
Basic Arithmetic Operations
print(5 + 5)
print(5 - 5)
print(5 * 5)
print(5 / 5)
print(20 + 0.123)
print(10 * 'Hello World!')
I was initially surprised by how simple math operations could be used in Python, but I quickly learned that even basic arithmetic has unique rules in programming. For instance, multiplying a string by an integer in this case print(10 * ‘Hello World’) results in the string being repeated 10 times. However, if you tried it with any other arithmetic operation: addition, subtraction, or division the output would result in an error since these operations are unsupported with strings.
Working with Variables and Inputs
variable_value = 246
variable_value = variable_value - 20
print(variable_value)
name = input('Enter your name: ')
print('Hello,' + name + '!')
Variables and inputs, variables serve as labels for storing data in Python this can include; ints, floats and strings variable_value = 246 while inputs read a line of text entered and return it as a string. The input() function prompts users to enter data, which is then stored in a variable and used to create an output. Although both seem similar, the sole difference would be that you can convert the input through each datatype.
For example, if the user wanted to know their height in centimetres, they could use this code:
height = float(input("Enter your height in meters: "))
print("your height in centimeters is " + str(height * 100) + "cm.")
These fundamental concepts have laid the groundwork for my Python journey, and I’m eager to dive deeper into more complex topics. Soon, I plan to explore functions and loops — key elements in writing efficient and powerful code. The path ahead is long, but with each step, I’m becoming more confident in my ability to code in Python.