Introduction To python (comments, variables, data types and numbers.)

emmanuel_nwachukwu_2f9d93

Emmanuel Nwachukwu

Posted on March 3, 2022

Introduction To python (comments, variables, data types and numbers.)

Python is one of the most widely used programming languages. Guido van Rossum created it, and it was released in 1991. It's used for server-side web development, software development, mathematics, and system programming just to mention.

Python is well-known for its general-purpose character, which makes it suitable for and the finest solution provider in practically any software development domain. Python is used in a variety of developing fields, including Data Science and Big Data Analytics. It is the most popular programming language and may be used to create any application.

A Python script which is essentially a file that contains a python code should have an extension .py and can be run from the command line by typing python file_name.py

characteristic Of Python

  • Python is a free and open source programming language that can be downloaded from the official website, with even its source code available.
  • Python can be used for rapid prototyping, or for production-ready software development.
  • Platform Independent, write once and run anywhere
  • python can connect to database systems. It can also read and modify files.

*python is used for *

  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.

Python Syntax compared to other programming languages

Python was designed for readability, and has some similarities to the English language with influence from mathematics.
Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.

My First Python Program

print ("hello world")
Enter fullscreen mode Exit fullscreen mode

then run the program and the output below will be displayed

hello World
Enter fullscreen mode Exit fullscreen mode

Python Comments

Comments can be used to explain Python code.

Comments can be used to make the code more readable.

Comments can be used to prevent execution when testing code.

To begin creating a comment in python we utilize the hash symbol (#)
If we have comments that span multiple lines, multi-line comments we can use the hash symbol at the start of each line . Another option is to use triple quotes such as ''' or """

# This is a single line comment

'''
multiline comment
This comment is written in more than one line
'''
Enter fullscreen mode Exit fullscreen mode

A comment does not have to be text that explains the code, it can also be used to prevent Python from executing code:

#print("Good, Mercedes!")
print("Cheers, lasucbt")
Enter fullscreen mode Exit fullscreen mode

when you run your code the output below will be displayed

Cheers, lasucbt
Enter fullscreen mode Exit fullscreen mode

conclusion
Comments can be used to explain Python code. Comments can be used to make the code more readable. Comments can be used to prevent execution when testing code.

Python Variables

Variables are names that are connected to a specific object in Python. They keep a reference to the memory address where an item is stored, often known as a pointer.
Variables are containers for storing data values.
The syntax is as follows:

variable_name = variable_value
Enter fullscreen mode Exit fullscreen mode

Creating Variables
Python has no command for declaring a variable.

A variable is created the moment you first assign a value to it.

x = 5
y = "John"
print(x)
print(y)
Enter fullscreen mode Exit fullscreen mode

when you run the code the output below will be displayed

5
John
Enter fullscreen mode Exit fullscreen mode

Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables:
A variable name must start with a letter or the underscore character
A variable name cannot start with a number
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Variable names are case-sensitive (age, Age and AGE are three different variables)

Always name your variables in a way that is both intuitive and readable.
Uppercase and lowercase letters (A-Z, a-z), numerals (0-9), and the underscore character (_) can all be used in variable names.
Variable names may contain digits, but the initial character must not be a numeric.

Variables do not require declaration. Python is a dynamically typed language since their data types are deduced from their assignment statement. This means that throughout the code, different data types might be given to the same variable.

Below are examples:

first_name = "elijah"
print(first_name)

middle_name = "khalifa"
print(middle_name)

last_name = "joy"
print(last_name)
Enter fullscreen mode Exit fullscreen mode

Run the code and the output below will be displayed

elijah
khalifa
joy
Enter fullscreen mode Exit fullscreen mode

Python allows you to assign values to multiple variables in one line:

x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
Enter fullscreen mode Exit fullscreen mode

Run the code and the output below will be displayed

Orange
Banana
Cherry
Enter fullscreen mode Exit fullscreen mode

Conclusion
python variables has different segments under it like

  • variable names
  • assign multiple variables
  • output variables
  • global variables

Like any other programming language, the concept of variables plays a significant role in python. The classified number of functionalities and flexibility in coding them make variables more precise entities for access in the python programming language.
A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing.

Python Data Types
Built-in Data Types
In programming, data type is an important concept.

Variables can store data of different types, and different types can do different things.

Python has the following data types built-in by default, in these categories:

Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview

Python Numbers

There are three numeric types in Python:
int
float
complex
.

💖 💪 🙅 🚩
emmanuel_nwachukwu_2f9d93
Emmanuel Nwachukwu

Posted on March 3, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Learning Python
javascript Learning Python

November 28, 2024

Calculate savings with Python!
beginners Calculate savings with Python!

November 26, 2024

UV the game-changer package manager
programming UV the game-changer package manager

November 24, 2024

Beginners Guide for Classes
python Beginners Guide for Classes

November 20, 2024