Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,606 members, 7,812,987 topics. Date: Tuesday, 30 April 2024 at 01:42 AM

Learn Python- Introduction To Programming - Programming (3) - Nairaland

Nairaland Forum / Science/Technology / Programming / Learn Python- Introduction To Programming (9499 Views)

My Journey To Programming / Are You New To Programming? Want To Learn But Do Not Know How? Come In! (2) (3) (4)

(1) (2) (3) (Reply) (Go Down)

Re: Learn Python- Introduction To Programming by Nobody: 12:24pm On Aug 30, 2017
Nastydroid:
he is trolling on you bro.
oh
Re: Learn Python- Introduction To Programming by Nobody: 3:48pm On Aug 30, 2017
samyomz:
so before i can know python, i have to know html?

Html4 is the easiest language to learn. If you can put it the effort to at least understand the structure of a web page, you should be good with good with python.

This is true because you need to understand that your going to troubleshoot half your time when your learning. Since html is easy, you get that response from your effort faster and you understand that you can google/bing/yahoo/yandex your way to success.

It psychological reinforcement - the fastest path to pay off which forces you to learn the fundamentals of completing any task in IT.
Re: Learn Python- Introduction To Programming by Sync201(m): 4:06am On Aug 31, 2017
I will continue the tutorial

An example of for loop

c=[ 'pen', 'book']
x=0
for i in c:
x+=1
print(i,x)

===≠=
Output
====≠
>>>pen 1
>>>book 2

=======
EXPLANATION
=======
The for loop basically declares the variable 'i' and assigns it to each list item as it goes through the loop.
The loop goes through two iteration as there are two items in the list in this case. The value of 'i' changes accordingly as the for loop goes though the list



During the 1st iteration, i == pen and x=1
During the 2nd iteration, i == book and x=2
Re: Learn Python- Introduction To Programming by chukzyfcbb: 8:16pm On Sep 24, 2017
please I am a novice in programming who can share me download links to learning python
both PDF and video. lemme start by October and start reading so by January, I should be fortified
Re: Learn Python- Introduction To Programming by dhananjayag789: 12:53pm On Mar 14, 2018

1 Like

Re: Learn Python- Introduction To Programming by Nobody: 10:10pm On Mar 15, 2018
Hey stealthtiger, I just pmed you..kindly reply so I can discuss some projects with you..cheers
Re: Learn Python- Introduction To Programming by stealthtiger(m): 10:48pm On Apr 10, 2018
enyinna4:
Hey stealthtiger, I just pmed you..kindly reply so I can discuss some projects with you..cheers

Please can you pm me again.
Re: Learn Python- Introduction To Programming by Vecto(m): 8:17am On Apr 11, 2018
stealthtiger:
Hi to everyone who opens this thread.
I'm Emmanuel Olatunde Bashorun and I'm 19 years also an undergraduate of the Univerisity of Lagos, and I love coding.
I'm so glad you're here and I'm assuming you're here to get a basic understanding about Python.

For those asking what language should I learn first let me give it to you bluntly and authoritatively learn Python if you want your life to be easier as you brave through the jungle of coding. I say Python because that's the best way to learn programming
Thank me later wink

What's Python;
Python is a high level language created by Guido Von Rossum in the late 1980's.
It has an efficient high level data structure and a simple but effective approach to object oriented programming. Python's elegant syntax and dynamic typing together with its interpreter makes it an ideal language for scripting and rapid application development in many areas and on most platforms.

Python is used in big multi organizations for software development and data management, Artificial Intelligence(on which lies my intrest). Its popular in companies and gorvernment organizations like CIA, disney, Google, Yahoo, Instagram, NASA, CERN etc.

Why learn programming: Programming is a skill which would determine your employability in the future in whatever field you're in. This is due to the increasing complexity of machines that'd be built and task's that needs to be solved. Let's say a sociologist is doing a Social computing test on Facebook and needs to know the most used words in a series of posts. Let's say 1million posts. It'd be so difficult but not impossible for the Sociologist to carry out that manually. It'd take a lifetime to get the required info from that task.
So if the person had a basic idea of programming say Python, within a couple of minutes the Sociologist would have written a program that solved that task elegantly.
In essence, you don't have to be a computer scientist to learn programming. After all the purpose of this tutorial is not to make you an accomplished Python developer but give you the required knowledge in getting started with python and doing some really incredible stuffs. At least it'd be a launch pad to lift your self into levels that will make you an accomplished Python developer.

The version of Python that would be used in this tutorial is version 3.4.5.
You can download and install Python on your PC as www.python.org.
CPython is the flavor of Python we'd be coding with.

Interpreter: Computers don't understand the normal language we speak so we have to communicate to them in a way they understand which is zero and ones called machine language which is represented by the switching on and off of the electrical circuits in the computer's memory. But it's difficult to write a string of zeros and ones telling a machine to get data from a user, process it and send it to the server which then gives any one who requests for it. Only a few people can do that now.
So how do we go round this problem. A high-level language is needed of which we understand .
High level languages are good because they require a shorter amount of time to write a program, they're portable, meaning they can run on different computers without modifications unlike machine language written on an Intel x84 based PC which has to be rewritten to run on an Intel x64 based PC.

Two programs process high level languages into machine language. 1. Interpreter 2. Compiler
The interpreter reads a high level language and executes it. It processes a program little at a time. Alternatively reads the code line by line and performing computations.

The compiler reads the whole program and translate everything before it starts running. In context the high-level program code is called SOURCE CODE and the translated code is called OBJECT OR EXECUTABLE CODE.

What is a program: [/b]A program is a series of instructions that tells a computer how to perform a computation.

[b]Tutorial Outline:

1. Variables, expressions and statements
2. Numerical Operations
3. Conditional statements
4. Functions
5. Loops
6. Strings
7. Dictionaries
8. Tuples
9. Files
10. Exception handling


PLEASE AND PLEASE NOTHING SHOULD BE POSTED ON THIS THREAD THAT IS OUT OF CONTEXT OF IT'S CONTENT AND THAT HAS THE ABILITY TO DERAIL THIS THREAD OF IT'S PURPOSE OTHERWISE A BAN WOULD BE GIVEN TO SUCH INDIVIDUAL.

Contextual and related contributions are welcome.

I'd be pleased if my errors can be pointed out during the cause of this tutorial since no one is perfect.

Every example that'd be given here has been tested. But self testing the examples is highly encouraged to see if it truly works and also to increase the rate of learning.

Before we get started let me leave you with one of my favorite quotes 'every skill you acquire doubles your odd of success' Scot Adams.

So at least we have a basic idea of what python is. So it's time to start getting our hands dirty in code.

1. Variables, Expressions and Statements
Let's hink of variables as containers. They hold values.
Variables in python are capable of holding different datatypes. Data types are types of data.
In python there are different data types such as int(integers=>they hold decimal numbers), float(floats=> numbers that contain decimal parts eg 8.76), str'(=> they are characters made up of a string of text eg 'good', 'Hello') there are other datatypes​ but we'd talk about them later

As I said earlier on that variables hold values.
Just like a jug holding some water or juice. Water andjuice are different types of liquid.
You don't have to tell the jug what substance your filling it with. It just holds it for you.

Same way with python. Python is an untyped language meaning you don'thave to specify to Python what type of value you're storing in the variable.

Eg.
>>> python = 'language'
>>>print(python)
>>>language
From the above example you can see that I didn't have to tell python what type of variable language is. Python automatically new that it's a string.

Check this out to confirm my statement above
>>>type('language')
>>>('type str')
So Python's so smart that it knows 'language' is a string. This ability is due to the fact that Python has an in-built function called type[\b]

In programming context storing a value in a variable is called [b]assigning a value to a variable
. So we assigned language to python.

Naming variables
In Python a variable name can not start with a number. That's an illegal variable name.
A variable name can contain an underscore, lower case, upper case.
You can't use a key word as a variable name. There are about 31 keywords in python (reserved words)
I strongly advise you to start your variable​ with a small letter.


>>>7_wonders= 'pyramid of Egypt'
SyntaxError: invalid syntax

>>> my_name = 'Bashorun'
>>>

>>> print = 'print is a keyword'
>>> SyntaxError: invalid syntax


Operator's:
These are symbols used to perform numerical operations like addition,subtraction, multiplication, division.

Expressions:
An expression is a combination of values, symbols and variables, operator's
16+2, 18-9 are expressions.

Statements: A statement is a unit of code that a python interpreter can execute.
Eg print statement and assignment statement.
Statements do not contain values while expressions do.

In Python there are different ways in which you can write your code. Either in the interactive mode or script mode.
Interactive: You write directly in the interpreter thereby make the interpreter execute your code line by line.

>>> pizza = 2.0
>>>people = 8.0
>>>shared_pizza = pizza/people
>>>print(shared_pizza)
>>>0.25

So you can see that Python keeps track of every line in the interactive mode

Script: in script mode each computation performed on a line doesn't show but it's actually calculated but doesn't display it's self until you tell Python to.
The final answer would be displayed after running the program written in the editor.
This is unlike the interactive mode where a result would be displayed for every computation performed on a line.
A text-editor is usually used in script mode, and Python comes with that editor which also has a debugger.

pizza = 2
shared = pizza * 8

After you run the code
16 would be printed on the IDLE interpreter.

Order of Operations:
PEMDAS
P: Parentheses
E: Exponentiation
M: Multiplication
D: Division
A: Addition
S: Subtraction
The first Operation takes precedence over the succeeding operation in an expression .

String operation: There are ways to manipulate string's both legal and illegal.
'school'/2 is an illegal operation. You can't divide a string

'school' * 2 is a valid operation which prints=> school school

There's a technique in programming called CONCATENATION. This means you can add two strings together to give the sum of the two strings
'spam' + 'spam' = spamspam

NB=> Anything​ enclosed in a single quote or double quote in python is called a string.

Eg. '32' is a string.
Since it's in a single quote python doesn't regard it as an integer

Comments
As you write complex programs, you'd need to know what a certain function does or what a certain variable stores just to remember. You'd be surprised 6 months later that you wouldn't be able to recognize your own code.
So this is where the comments shines.
A comment is created by using a # sign
#my_name is a comment which stores Bashorun
my_names = 'Bashorun'

When you run the following code, the python interpreter ignores the line that starts with a #

Bro, can we talk on whatsapp?
Re: Learn Python- Introduction To Programming by adebayoabigeal: 8:48am On Apr 11, 2018
Please i really wish to learn python programming language, i would appreciate it if you can send your WhatSapp contact to: ayoadejohnk@gmail.com. Thanks
Re: Learn Python- Introduction To Programming by Vecto(m): 9:32am On Apr 11, 2018
adebayoabigeal:
Please i really wish to learn python programming language, i would appreciate it if you can send your WhatSapp contact to: ayoadejohnk@gmail.com. Thanks

Same here. I tried learning with Java c ++ but it wasn't sinking in.
Re: Learn Python- Introduction To Programming by Vecto(m): 9:33am On Apr 11, 2018
Please kindly forward your contact to Arshraaf@gmail
com.
Re: Learn Python- Introduction To Programming by dauddy97(m): 9:35am On Apr 11, 2018
Op, you have been doing a great job. But,it a while you posted and update your topic "python". For thoes asking for contact or the other. Pls,discard their comments and focus on this thread. Many have benefited and will still be benefited. Pls,continue and i wish all python programmers out there the very best.
Re: Learn Python- Introduction To Programming by Vecto(m): 9:48am On Apr 11, 2018
dauddy97:
Op, you have been doing a great job. But,it a while you posted and update your topic "python". For thoes asking for contact or the other. Pls,discard their comments and focus on this thread. Many have benefited and will still be benefited. Pls,continue and i wish all python programmers out there the very best.

Bros relax.


The reason why I asked for his contact is this.

I have zero knowledge of programming, hence, I need someone who can explain from the basics. I stumbled upon this thread while searching for tutorials on how to learn programming for beginners. I read half way but I'm still confused. I have a friend who knows how to code but he doesn't have time.

He just leaves me with his laptop with a bunch of tutorials as guide through. Like right now I'm just staring at it. It's all Greek to me.
Re: Learn Python- Introduction To Programming by Nobody: 1:16pm On Apr 11, 2018
stealthtiger:
Hi to everyone who opens this thread.
I'm Emmanuel Olatunde Bashorun and I'm 19 years also an undergraduate of the Univerisity of Lagos, and I love coding.
I'm so glad you're here and I'm assuming you're here to get a basic understanding about Python.

For those asking what language should I learn first let me give it to you bluntly and authoritatively learn Python if you want your life to be easier as you brave through the jungle of coding. I say Python because that's the best way to learn programming
Thank me later wink

What's Python;
Python is a high level language created by Guido Von Rossum in the late 1980's.
It has an efficient high level data structure and a simple but effective approach to object oriented programming. Python's elegant syntax and dynamic typing together with its interpreter makes it an ideal language for scripting and rapid application development in many areas and on most platforms.

Python is used in big multi organizations for software development and data management, Artificial Intelligence(on which lies my intrest). Its popular in companies and gorvernment organizations like CIA, disney, Google, Yahoo, Instagram, NASA, CERN etc.

Why learn programming: Programming is a skill which would determine your employability in the future in whatever field you're in. This is due to the increasing complexity of machines that'd be built and task's that needs to be solved. Let's say a sociologist is doing a Social computing test on Facebook and needs to know the most used words in a series of posts. Let's say 1million posts. It'd be so difficult but not impossible for the Sociologist to carry out that manually. It'd take a lifetime to get the required info from that task.
So if the person had a basic idea of programming say Python, within a couple of minutes the Sociologist would have written a program that solved that task elegantly.
In essence, you don't have to be a computer scientist to learn programming. After all the purpose of this tutorial is not to make you an accomplished Python developer but give you the required knowledge in getting started with python and doing some really incredible stuffs. At least it'd be a launch pad to lift your self into levels that will make you an accomplished Python developer.

The version of Python that would be used in this tutorial is version 3.4.5.
You can download and install Python on your PC as www.python.org.
CPython is the flavor of Python we'd be coding with.

Interpreter: Computers don't understand the normal language we speak so we have to communicate to them in a way they understand which is zero and ones called machine language which is represented by the switching on and off of the electrical circuits in the computer's memory. But it's difficult to write a string of zeros and ones telling a machine to get data from a user, process it and send it to the server which then gives any one who requests for it. Only a few people can do that now.
So how do we go round this problem. A high-level language is needed of which we understand .
High level languages are good because they require a shorter amount of time to write a program, they're portable, meaning they can run on different computers without modifications unlike machine language written on an Intel x84 based PC which has to be rewritten to run on an Intel x64 based PC.

Two programs process high level languages into machine language. 1. Interpreter 2. Compiler
The interpreter reads a high level language and executes it. It processes a program little at a time. Alternatively reads the code line by line and performing computations.

The compiler reads the whole program and translate everything before it starts running. In context the high-level program code is called SOURCE CODE and the translated code is called OBJECT OR EXECUTABLE CODE.

What is a program: [/b]A program is a series of instructions that tells a computer how to perform a computation.

[b]Tutorial Outline:

1. Variables, expressions and statements
2. Numerical Operations
3. Conditional statements
4. Functions
5. Loops
6. Strings
7. Dictionaries
8. Tuples
9. Files
10. Exception handling


PLEASE AND PLEASE NOTHING SHOULD BE POSTED ON THIS THREAD THAT IS OUT OF CONTEXT OF IT'S CONTENT AND THAT HAS THE ABILITY TO DERAIL THIS THREAD OF IT'S PURPOSE OTHERWISE A BAN WOULD BE GIVEN TO SUCH INDIVIDUAL.

Contextual and related contributions are welcome.

I'd be pleased if my errors can be pointed out during the cause of this tutorial since no one is perfect.

Every example that'd be given here has been tested. But self testing the examples is highly encouraged to see if it truly works and also to increase the rate of learning.

Before we get started let me leave you with one of my favorite quotes 'every skill you acquire doubles your odd of success' Scot Adams.

So at least we have a basic idea of what python is. So it's time to start getting our hands dirty in code.

1. Variables, Expressions and Statements
Let's hink of variables as containers. They hold values.
Variables in python are capable of holding different datatypes. Data types are types of data.
In python there are different data types such as int(integers=>they hold decimal numbers), float(floats=> numbers that contain decimal parts eg 8.76), str'(=> they are characters made up of a string of text eg 'good', 'Hello') there are other datatypes​ but we'd talk about them later

As I said earlier on that variables hold values.
Just like a jug holding some water or juice. Water andjuice are different types of liquid.
You don't have to tell the jug what substance your filling it with. It just holds it for you.

Same way with python. Python is an untyped language meaning you don'thave to specify to Python what type of value you're storing in the variable.

Eg.
>>> python = 'language'
>>>print(python)
>>>language
From the above example you can see that I didn't have to tell python what type of variable language is. Python automatically new that it's a string.

Check this out to confirm my statement above
>>>type('language')
>>>('type str')
So Python's so smart that it knows 'language' is a string. This ability is due to the fact that Python has an in-built function called type[\b]

In programming context storing a value in a variable is called [b]assigning a value to a variable
. So we assigned language to python.

Naming variables
In Python a variable name can not start with a number. That's an illegal variable name.
A variable name can contain an underscore, lower case, upper case.
You can't use a key word as a variable name. There are about 31 keywords in python (reserved words)
I strongly advise you to start your variable​ with a small letter.


>>>7_wonders= 'pyramid of Egypt'
SyntaxError: invalid syntax

>>> my_name = 'Bashorun'
>>>

>>> print = 'print is a keyword'
>>> SyntaxError: invalid syntax


Operator's:
These are symbols used to perform numerical operations like addition,subtraction, multiplication, division.

Expressions:
An expression is a combination of values, symbols and variables, operator's
16+2, 18-9 are expressions.

Statements: A statement is a unit of code that a python interpreter can execute.
Eg print statement and assignment statement.
Statements do not contain values while expressions do.

In Python there are different ways in which you can write your code. Either in the interactive mode or script mode.
Interactive: You write directly in the interpreter thereby make the interpreter execute your code line by line.

>>> pizza = 2.0
>>>people = 8.0
>>>shared_pizza = pizza/people
>>>print(shared_pizza)
>>>0.25

So you can see that Python keeps track of every line in the interactive mode

Script: in script mode each computation performed on a line doesn't show but it's actually calculated but doesn't display it's self until you tell Python to.
The final answer would be displayed after running the program written in the editor.
This is unlike the interactive mode where a result would be displayed for every computation performed on a line.
A text-editor is usually used in script mode, and Python comes with that editor which also has a debugger.

pizza = 2
shared = pizza * 8

After you run the code
16 would be printed on the IDLE interpreter.

Order of Operations:
PEMDAS
P: Parentheses
E: Exponentiation
M: Multiplication
D: Division
A: Addition
S: Subtraction
The first Operation takes precedence over the succeeding operation in an expression .

String operation: There are ways to manipulate string's both legal and illegal.
'school'/2 is an illegal operation. You can't divide a string

'school' * 2 is a valid operation which prints=> school school

There's a technique in programming called CONCATENATION. This means you can add two strings together to give the sum of the two strings
'spam' + 'spam' = spamspam

NB=> Anything​ enclosed in a single quote or double quote in python is called a string.

Eg. '32' is a string.
Since it's in a single quote python doesn't regard it as an integer

Comments
As you write complex programs, you'd need to know what a certain function does or what a certain variable stores just to remember. You'd be surprised 6 months later that you wouldn't be able to recognize your own code.
So this is where the comments shines.
A comment is created by using a # sign
#my_name is a comment which stores Bashorun
my_names = 'Bashorun'

When you run the following code, the python interpreter ignores the line that starts with a #


I've sent an email. here is my email add onwuzuruikemichael72@yahoo.com
I await yours
Re: Learn Python- Introduction To Programming by dauddy97(m): 9:08am On Apr 13, 2018
Vecto:


Bros relax.


The reason why I asked for his contact is this.

I have zero knowledge of programming, hence, I need someone who can explain from the basics. I stumbled upon this thread while searching for tutorials on how to learn programming for beginners. I read half way but I'm still confused. I have a friend who knows how to code but he doesn't have time.

He just leaves me with his laptop with a bunch of tutorials as guide through. Like right now I'm just staring at it. It's all Greek to me.
ok,may god help us all. Success in your programming
Re: Learn Python- Introduction To Programming by Avast(m): 8:39pm On Dec 19, 2018
anyone still here?
I am new to Python, have migrated to using NUMPY and PANDAS on Jupyter because I want to go into . I am looking for where to apply my knowledge or to lay my hands on real life data.
Re: Learn Python- Introduction To Programming by umarfaruq1805: 11:44pm On Dec 19, 2018
Leggo. I've been studying the python language for about 2 weeks now, your explanation just made me understand some concepts. Kudos

(1) (2) (3) (Reply)

Using Finger Print Scanner On PHP / Is 5 Months Enough To Learn Java? / Q-basic Program To Compute Simple Interest.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 62
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.