How Easy Coding is to Get Started with Python

How Easy Coding is to Get Started with Python

Simply write down your first code in Python. Most probably, Python is the easiest programming language in the world. The syntax and functions of this programming language are similar to the English language, making Python code more readable and easy to learn. Many people try to memorize code, which is the wrong approach. Every beginner falls into this mistake, resulting in spending more time learning the code. Over time, they lose patience and distance themselves from learning.

However, if they try to learn coding by having fun, they will continue. In this article, we will learn Python in the easiest way possible. Let’s get started.

Using the “print” statement, we display the output of a code.

print("data injector")

Output:data injector

Great! We’ve written our first Python code. How easy is this?

To print an output value, we can simply use the “print” method, opening and closing with parentheses, then placing our data inside double quotes that we want to print. These double quotes indicate that the data or value we want to print is a string. If there are no double or single quotes, it means it’s an integer or float number. Now, let’s take a numerical value that is not a string and we want to print it.

print(1997)

In this case, the output will print 1997 as a string. You can’t use this output as a number. It cannot perform addition, division, multiplication, or any mathematical operations. Therefore, if you want to print a numerical value, you shouldn’t use single or double quotes.

print(1997 + 5)


But when you use single or double quotes, it will concatenate the values:

print("1997" + "5")

This value is concatenated with another value. Now, let’s discuss “concatenate”.

If we want to add two strings together using the + symbol, that’s called concatenation.

print("Nolan " + "is a film maker")

Variables: Let’s talk about variables. A variable is like a container that holds a value, which can be a string, numerical number, characters, list, or dictionary, etc.

We can set the variable name as we like, but there are some criteria for choosing a variable name:

  1. The variable name should be meaningful.
  2. It shouldn’t be a number.
  3. It shouldn’t start with a number.
  4. It shouldn’t have spaces within the variable name.
  5. It should start with a letter.
  6. If needed, use underscores (_) for spaces, like student_name = "Daniel". Here, student_name is a variable name, and "Daniel" is the value.

Let’s create a variable name and assign a value that we can use for multiple purposes:

a = 5
b = 2
div = a / b
multiplication = a * b
add = a + b
sub = a - b

print(div, multiplication, add, sub)

Here, a, b, div, multiplication, add, and sub are all variables. a and b contain numerical values. div, multiplication, add, and sub hold the results of specific operations.

We can also use the print function multiple times:

a = 5
b = 2
div = a / b
multiplication = a * b
add = a + b
sub = a - b

print(div)
print(multiplication)
print(add)
print(sub)


Another Example:


Here, we directly use a variable for arithmetic operations.

This lesson introduces how to print output and use variables in Python.

administrator

Related Articles

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *