DEV Community

Phylis Jepchumba, MSc
Phylis Jepchumba, MSc

Posted on

30DAYS OF PYTHON

Day 1 of the 30 Days Of Python.

  • What python is.
  • Python programming paradigms: Imperative, Functional, Procedural, Object-oriented paradigms

  • Representing data using python data types: Booleans, strings ,lists, tuples, sets, dictionaries.

  • Applications of Python in Software development and DevOps engineering automation, data science and machine learning.

  • PEP8 Rules

Python is an interpreted ,high-level ,general-purpose programming language used in web development, data science and creating software prototypes.

Python Paradigms.
Programming paradigms is a style or concept by which the methodology of a programming language adheres to.Python supports four programming paradigms:

  • Imperative-Python fully implements this paradigm. It uses statements that change a program state and focuses on how to solve.Data structures implement the use of this paradigm.

  • Functional- It is also known as declarative paradigm It treats every statement as a mathematical equation.
    in python, lambda and recursion are approaches used to implement functional programming paradigm.

  • Procedural- in this paradigm, computational tasks are treated as step by step iteration and common task grouped as functions.
    In python, procedural paradigm favors iterations, selection, sequencing and modularization.

  • Object-oriented- a programming paradigm that relies on concepts of classes and objects and focuses on writing reusable code. Python has object oriented features as methods, inheritance encapsulation and polymorphism.

Applications of Python.
  • Building desktop applications, including GUI applications, CLI tools, and even games
  • Building web and Internet applications- python offers frameworks such as Django and microframeworks such as flask for web developemnt.
  • Performing DevOps tasks- Python enables DevOps professionals to build, test, deploy, visualize and monitor the DevOps lifecycle with improved, simple custom utilities.DevOps tools such as Ansible is written in python.

  • Education-Python is a superb language for teaching programming, both at the introductory level and in more advanced courses.

Representing data using python data types.

Python has a handful of built-in data types, such as numbers (integers, floats, complex numbers), Booleans, strings, lists, tuples, dictionaries, and sets.

Numeric data type.

They represent the data that has a numeric value and can belong to three different numerical types:
Integers: Consists of positive or negative whole numbers.

a=12
print(a)
Enter fullscreen mode Exit fullscreen mode

Floats:Are true numbers with floating-point representation specified by a decimal point.

b=12.5
Enter fullscreen mode Exit fullscreen mode

Complex numbers: Are numbers with a real part and an imaginary part.

c=1.8j,3+4.5j
Enter fullscreen mode Exit fullscreen mode
String Datatype.

Strings are pieces of text or sequences of characters that you can define using single, double, or triple quotes:

# Use single quotes
print('Hello there!')
'Hello there!'
#Use double quotes
greeting = "Good Evening!"
print(greeting)
'Good Evning!'
# Use triple quotes
message = """30 Days of Python Challenge!"""
print(message)
'30 Days of Python Challenge!'
Enter fullscreen mode Exit fullscreen mode

String data type can be used for Concatenation, Slicing, and Repetition.
Concatenation-Joining two or more strings together.

print("My name is" + " " + "Korir")
#output
'My name is Korir'
Enter fullscreen mode Exit fullscreen mode

Repetition-It is repeating a sequence of instructions a certain number of times.

a='phy'
print(a*5)
Output: phyphyphyphyphy
Enter fullscreen mode Exit fullscreen mode

Slicing- used extract different parts of a string.

String1 = "Python"
print(String1[3:4])
output=h
Enter fullscreen mode Exit fullscreen mode
List Data Type.

Lists are used to store multiple items in a single variables.
Lists are defined in Python by enclosing a comma-separated sequence of objects in square brackets ([]), as shown below:

numbers=[1,2,3,4,5,7]
print(numbers)
output: [1, 2, 3, 4,5,7]
Enter fullscreen mode Exit fullscreen mode

Characteristics of Python Lists.

  • Lists are ordered.
  • Lists can contain any arbitrary objects.
  • List elements can be accessed by index.
  • Lists can be nested to arbitrary depth.
  • Lists are mutable.
  • Lists are dynamic.
Tuples Data type

Tuples are identical to lists in all respects, except for the following properties:

  • Tuples are defined by enclosing the elements in parentheses (()) instead of square brackets ([]).
  • Tuples are immutable hence cannot be modified
  • Execution is faster when manipulating a tuple Here is an example of a tuple:
tuple1=(11,2,43,4)
print(tuple1)

output: (11, 2, 43, 4)
Enter fullscreen mode Exit fullscreen mode
Dictionaries Data type

Dictionary in python is an ordered collection, used to store data values.
You can define a dictionary by enclosing a comma-separated list of key-value pairs in curly braces ({}). A colon (:) separates each key from its associated value.

new_dict = {"firstname": "Korir", "lastname": "Mary",
  "DOB": 2000}
print(new_dict["lastname"])
output:"Mary"
Enter fullscreen mode Exit fullscreen mode
Set Data Type.

used to store multiple items in a single variable.
Every set element is unique and must be immutable.
Are created by placing all the items inside curly braces {}, separated by comma, or by using the built-in set() function.

new_set = {1, 2, 3,4,5}
print(new_set)

output={1, 2, 3, 4, 5}
Enter fullscreen mode Exit fullscreen mode

Resources

Top comments (0)