PYTHON FOR NEWBIES

lewanja

Leah Ndirangu

Posted on February 14, 2022

PYTHON FOR NEWBIES

GETTING STARTED

Python programming language is a high level, general purpose language. This means that it is written in human readable language and designed to solve a particular problem.
Python is suitable for including but not limited to:

  • Web Development
  • Data Science
  • Machine Learning
  • Game Development
  • Data Engineering
  • Robotics
  • Automation

INSTALLING PYTHON

To install python visit: Python, scroll down to active releases to see which version is secure for download.
NOTE:
Python 2.7 is no longer in use.
Once you've settled on a specific version, select download to download
Take note of the operating system your machine uses before download.

Python on visual-studio and pycharm:

To get started with python on visual-studio, follow Getting Started with Python in VS Code and pycharm Get Started

WRITING YOUR FIRST PROGRAM

Python uses print function to output text to the console/command line. Print must be followed by a parenthesis which encloses the output we want to generate. Open your command line interface (CMD in Windows, terminal in Mac and Linux) and type the code snippet below then press enter

print("My name is Jane Doe")
Enter fullscreen mode Exit fullscreen mode

Feel free to modify the code with various other inputs

A variable is used to store a value. It can e on of the various inbuilt python types or custom types, but for now we shall use the inbuilt python types i.e

  • Numbers e.g.
num1 = 1 # type int
num2 = 8.6 # type float
Enter fullscreen mode Exit fullscreen mode
  • List - this holds several items of the same or different types e.g.
numbers=[1,2,3,]
letters = ['a', 'b', 'test']
empty_list = []
Enter fullscreen mode Exit fullscreen mode
  • String - this is a combination of letters or numbers in any order, commonly known as word or sentence. You can use both single and double quotes to denote a string, just make sure to match the start and the end e.g. Sample code :
string_1 = 'My name is Jane Doe' # sample using single quotes
string_2 = "1" # sample using double quotes
string_3 = "a3923"
string_4 = " "
Enter fullscreen mode Exit fullscreen mode
  • Tuple - this is similar to a list, just that its contents cannot be changed. Declare one using the syntax below
my_tuple = (1,2,3,4,)
Enter fullscreen mode Exit fullscreen mode
  • Dictionary - This is used to hold key value pairs, e.g. students and their marks
students = {
       "john" : 35,
       "jane": 24,
       "alice": 99,
       "peter": 1
}
Enter fullscreen mode Exit fullscreen mode

You can assign a variable to hold your name and change it during runtime for example

name= "Jane Doe"
print(name)
Enter fullscreen mode Exit fullscreen mode

Arithmetic operators

Operator Description Syntax
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Modulus a%b
// Quotient a//b
** Exponent a**b
a=10
b=6
c=2

print(a+b)
print(a-b)
print(a*b)
print(a/c)
print(a%b)
print(a%c)
print(a//b)
print(a//c)
print(a**b)
print(a**c) 
Enter fullscreen mode Exit fullscreen mode

Logic Operators

Operator Description Syntax
and True if both operands result is true a and b
or True if either operands result is true a or b
not True if both operands result is false a not b

REFERENCES

Python Download Page
Pycharm Download Page
VS Code Python Docs

💖 💪 🙅 🚩
lewanja
Leah Ndirangu

Posted on February 14, 2022

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

Sign up to receive the latest update from our blog.

Related