How To Write A Simple Python Program In 6 Easy Steps

Profile image for Farooq Sheikh
Farooq Sheikh Full Stack Developer | Nodejs, mongodb, Reactjs
Dec 25, 2021 ‧ 3 min read
Series (1 Parts): Python Basics

Python is a general purpose programming language. Python is used to do the following: 

1)Python can be used to analyze data. 

2)It can be used to create graphics and visualizations. 

3)It can be used as a scripting language. 

4)It can be used to create games and animations. 

What is the Python Programming Language and How is it Used? 

The Python programming language is one of the most popular programming languages in the world. It is powerful, versatile and easy to learn. 

Python is a general-purpose, high-level programming language. Python was designed with code readability in mind and has a relatively clear syntax. 

There are many reasons why Python might be your best choice for your first introductory programming language. For starters, it's free and open source under an MIT license! 

It’s also compatible with virtually every operating system out there (Windows, MacOSX, Linux), which means that you'll be able to compile and execute your programs on any machine without trouble. 

Python also has an extensive library of third-party libraries that can help you out with just about anything starting from image processing. 

Python Syntax & Variables 

Python is a programming language that allows for quick and easy scripting, making it ideal for data analytics. 

Python syntax is similar to other popular programming languages like Java or C++. Variables in python are declared with the assignment operator ‘=’. The variable name should start with a letter, not contain numbers, and cannot be a reserved word. Lists are created by using square brackets or parentheses. 

Variables in Python are used to store data values in the program's memory, so the code can access them when needed. A list of variables in Python would include string, integer, float, datetime etc. 

Python Operators 

Operators are instructions that tell the computer what to do. It is important for developers to know the different types of operators in order to code more efficiently. 

A few examples of operators are: 

+ (plus sign) - (minus sign) / (slash) * (asterisk) % (percent sign) // (double slash) 

Data Types in Python 

A data type in Python is a classification of the kind of data that it is. 

The data types can be classified into mutable and immutable. 

Data types in Python include: strings, integers, floating point numbers, complex numbers, tuples, lists and dictionaries. 

Control Statements in Python Programs - "If" Statements and Else Clauses 

Control statements in Python programs are the way to tell the program how it should behave. There are two types of control statements: if statements and else clauses. The if statement is used when we want to run a certain command, only if a certain condition is met. If the condition is not met, then we use an else clause to tell Python what should happen next. 

Conclusion - Wrap Up on Writing a Simple Python Program 

We have covered the basic structure of a Python program. The control statements that are available in Python are the ‘If statement and Else clause’. 

We will now look at some examples of how these can be used. 

If Statements: The "if" statement is used to execute a block of code if a specified condition evaluates to True. For example, suppose we want to print out “Hello” only when x has the value 10, we can do so using the following code: 

x = 10 if x == 10: print("Hello") 

An "if" statement consists of two parts, an "if" condition and what to do if it's true (or false). After an "if" condition is stated, you need to put parentheses. 

Happy coding, keep learning, and practicing to become an expert! 

Posted on Dec 25, 2021 by:
Profile image for Farooq Sheikh
Farooq Sheikh
Full Stack Developer | Nodejs, mongodb, Reactjs
PythonJavaSpringCNode.jsReactjs +1

Comments

Profile image for Farooq Sheikh

Full Stack Developer | Nodejs, mongodb, Reactjs

PythonJavaSpringCNode.jsReactjs +1
2.4K
Reputation
199
Following
242
Followers