[go: up one dir, main page]

0% found this document useful (0 votes)
21 views11 pages

CT Hndpyth

Uploaded by

samadjunior7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views11 pages

CT Hndpyth

Uploaded by

samadjunior7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

LIST

This allows you to work with a list of values and is mutable (changeable, editable). [ ] is the
symbol used in a list.

SET

This is a collection of values with no duplicates where outputs keep changing when run multiple
times.

TUPLE

This also allows you to work with a list of values that is immutable (cannot be changed or edited)

( ) is the symbol used in a tuple.

FUNCTIONS THAT ARE USED IN A LIST

1. APPEND
2. EXTEND
3. POP
4. INSERT
5. REMOVE
6. INDEX uses [ ]
7. LEN

All functions are in lower cases.

Example

If you are to use append, you use it to add something to a LIST or replace something with
another. e.g. Take this List of subjects:

subjects = [‘CTE_323’,’COM_316’,’COM_325’]

When you are to append(add another course to the list above), just use the python command
below:

subjects.append(‘Agric’)

print(subject)

OUTPUT

subjects = [‘CTE_323’,’COM_316’,’COM_325’,’Agric’]
EXTEND

Given a list below:

first_name = [‘Jade’,’Joshua’,’Jamal’,’Jabar’]

last_name = [‘Bamidele’,’Bode’,’Braimah’,’Biliamin’]

first_name.extend(last_name)

print(first_name)

OUTPUT

[‘Jade’,’Joshua’,’Jamal’,’Jabar’,’Bamidele’,’Bode’,’Braimah’,’Biliamin’]

POP function

Using the above example in Extend, if you type first_name.pop() as shown below:

first_name = [‘Jade’,’Joshua’,’Jamal’,’Jabar’]

first_name.pop()

print(first_name)

OUTPUT

[‘Jade’,’Joshua’,’Jamal’]

Comment: Jabar has been removed from the list of names

REMOVE function

This is similar to pop() but you use it to specifically remove an item at any location in a List.

Example

first_name = [‘Jade’,’Joshua’,’Jamal’,’Jabar’]

first_name.remove(‘Joshua’)

print(first_name)

[‘Jade’,’Jamal’,’Jabar’]
INSERT (It is used to add to a specific location in a list)

first_name = [‘Jade’,’Joshua’,’Jamal’,’Jabar’]

first_name.insert(4,‘President_Tinubu’)

print(first_name)

OUTPUT

[‘Jade’,’Joshua’,’Jamal’,’Jabar’,’President_Tinubu’]

Comment

You must choose a location when using insert; it makes it different from append

Another example on INSERT

first_name = [‘Jade’,’Joshua’,’Jamal’,’Jabar’]

last_name = [‘Jide’,’Josh’]

first_name.insert(0, last_name)

print(first_name)

OUTPUT

[‘Jide’,’Josh’,‘Jade’,’Joshua’,’Jamal’,’Jabar’]

LEN function

It is used to count the number of items in a LIST.

first_name = [‘Jade’,’Joshua’,’Jamal’,’Jabar’]

print(len(first_name))

OUTPUT

[ ] This symbol is used to index in a list

For example, to access Jade

first_name = [‘Jade’,’Joshua’,’Jamal’,’Jabar’]

print(first_name[0])
OUTPUT

[‘Jade’]

Using same example, to print from Jade to Joshua or to index Jade and Joshua only, use the
code below to get 2 items from the list:

first_name = [‘Jade’,’Joshua’,’Jamal’,’Jabar’]

print(first_name[0:2])

OUTPUT

[‘Jade’,’Joshua’]

Change [0:2] to [0:3], then Jamal is added to get 3 items

OUTPUT

[‘Jade’,’Joshua’,’Jamal’]
Difference Between Tuple and List

Tuple is another sequence data type that is similar to the list. It consists of a number of values
separated by commas. Lists are enclosed in brackets [ ] and their elements and size can be
changed (mutable), while Tuples are enclosed in parentheses ( ) and cannot be updated, Tuple is
read only lists. e.g tuple = (‘abcd’,‘786’, ‘2.23’, ‘John’)

Types of arguments in python

1. Python Default
2. Python Keyword
3. Python Arbitrary

Operators that python support

1. Arithmetic Operator
2. Argument Operator
3. Logical Operator
4. Bitrise Operator
5. icantity Operator

Tuple

1. lagos_1 = [‘History’, ‘Math’, ‘Physics’, ‘Computer Science’]


2. lagos_2 = List_1
3. Print (lagos_1)
4. Print (lagos_2)

lagos_1 and lagos_2 will have the same output

5. lagos_1 (0) = ‘Art’


6. Print (lagos_1)
7. Print (lagos_2)

TUPLE

Same as above but if you change lagos_1 = tuple_1 and lagos_2 = tuple_2, also in the print
statements:

If you change any particularly in lines to tuple_1(0) = ‘Art’ you will receive an error code
because it is immutable.

If you want something you can modify, use list but use tuple if you are not ready to modify.
If you want something you can modify, use list but use are not modifying.

SET

CS_Courses= { ‘ History ’ , ‘ Math ’ , ‘ Physics ’ , ‘ Computer Science ’ }

print (CS_Courses)

OUTPUT

Output keeps changing in set when you run and rerun.

PYTHON PROGRAMMING

Python is a multipurpose programming long for variety of different tasks. It can be use for
machine learning and Al, data science projects, web developments.

it is the No 1 language for A1, machine learning and data science projects. Use python and a
framework of Django, one can build amazing websites. Website powered with Django are
Youtube, Sporty, Pinterest, Instagram, Dropbox. One can use python in Automation, it can save
your time in automating repetitive tasks.

The first thing is to head over to python.org and select the latest version of python (Go to
download, and select the latest version.

Install a code editor, e.g Most popular ( You will get it from jetlorams.com/pycharm). This is
used to write the code and execute it.

There are two download: The professional and community edition which is free and open source.

Pycharm
Either single or double quote is acceptable in python
print (“Hello.World”)/lower case

Strong or sequence of characters

PYTHON

An amazing programming application that can be used to develop any specific application right
from the social media apps like pinterest and instagram.
Python is available across many platforms including windows linux and MAC OS. Due to its
inherently easy to learn nature, along with its objects oriented features, python is used to develop
and demonstrate application quickly.

Python has the “batteries included” philosophy compared with the rich set of built-in libraries.

Hosting solution for python are very cheap.

IDENTIFIERS

At least one character must be used.

An Alphanumeric letter (Upper or Lowercase) must be the first character or an underscore.

e.g A B C D E F G H I J K L M N O P Q R S T U V W X Z Y

A B C D E F G H I J K L M N O P Q R S T U V W X Z Y_0 1 2 3 4 5 6 7 8 9

User Input

X=Input ( )

Print (“Please enter your matric number:”)

X= Input ( )

Print “Text entered:”, X)

Print (“Type:”, type (X))

Output

Please enter you matric number

12

Text Entered: 12

Type:<class ‘str;>

Topic: Evaluation (eval ( )) Functions

Num 1= eval (Input (‘please enter number:’))

Num 2= eval (Input (‘please enter number 2’))

Print (num 1, ‘+’ num 2, ‘=’, num 1 + num 2)

Please enter number 1, number 2: 23, 10 23 + 10 = 3


Controlling (Print ()) Function

Print (‘A’, end= ‘ ’)

Print (‘B’, end= ‘ ’)

Print (‘C’, and= ‘ ’)

Print ( )

Output

ABC

Python Expression and Operators

Num 1= eval (Input (‘Enter the first number:’))

Num 2= eval (Input (‘Enter the second number:’))

Sum=Num1 + Num2

Print (num1, ‘+’, num2, ‘=’, sum)

Output

Enter first number:12

Enter second number: 5

12+5 =17

While Loop

Count = 1

While count < = 5:

print (count)

count = 1

OUTPUT

2
3

Sum = 0

For n in range (1,100)

Sun = sum + n

Print (“Sum”, sum)

Sum 1

Sum 3

Sum 6

Sum 10

Sum 15

Sum 21

Sum 28

Sum 36

Sum 45

Sum 55

Sum 66

Sum 78

Sum 91

A loop that decrement in steps of 3 from 21 down to 3

Answer

for n in range (21, 0, -3):

Print (n)
Output

21 18 15 12 9 6 3

DEVELOPMENT TOOL

In the Data Science Community, Python is one of the most popular programming language. It is
popular because of the following reasons:

1. Python has a very simple syntax almost equivalent to mathematical syntax hence can be
easily understood and learned.
2. It offers extensive coverage libraries and tools for scientific imputing and data science

PYTHON TOOLS

1. Scikit learn: This is an open source tool depend for data science and machine leaning
engineer ,developers and data scientist for data mining and data analysis .it offer a consistent
and user ,friendly application program Interface (APL) along with grind and random searches
2. KERAS: This is an open source ,high level reduce network library written in python . suited
for machine leaning and deep leaning .four core principles of keras are user friendliness ,
modularity easy extensibility and working with python
3. THEANO: This is an python library designed exphaty for expressing must dimensional
arrays . It allows you to define optimize ,and evaluate mathematical computations comprising
multi-dimensional array
4. SAIPY: An open source python based library ecosystem used for scientific and technical
computing

ADVANCED PYTHON TOOLS

1. SELENIUM: Automation framework for web applications


2. ROBOT FRAMEWORK: For acceptance testing and acceptance test driven development
(ATTD)It is keyboard driven and user tabular test data syntax
3. Test complete: this is software support, web, mobile, and desktop automation testing
WEB SERACHING PYTHON TOOLS

1. Beautiful soup: python library for extracting data from HTML and XML files
2. LXML: python based tool for C – libraries : libxml2 and libxslt
3. SCRAPY: for developing web spiders that crawl website and extract data from them
4. URLLIB: for collecting and opening URLs

Python Installation Procedure


a) Type python.org (official website) in the web address bar of your web
browser and press enter on your keyboard.
b) Select the version of python to download by navigating to downloads for
windows, and click on the latest version of python depending on the version
you’re working with.
c) Select a link to download either the windows x86-64 executable installer or
the windows x86 executable installer.
d) Run the executable installer once downloaded.
e) Select the install launcher for all users and add python 3.7 to path
checkboxes
f) Verify python has been installed on windows

Pycharm Installation Procedure


A. Type jetbrains.com/pycharm in the web address bar and press the enter
key.
B. Navigate to the downloads, select the community edition (free and open
source) by clicking on it.
C. Run the executable installer
D. Verify the pycharm is installed on windows

You might also like