0% found this document useful (0 votes)
26 views4 pages

Python For Beginners 1

This document serves as a beginner's guide to learning Python, highlighting its ease of use, installation, and learning resources. It emphasizes Python's popularity, versatility in applications, and provides a simple example of checking for prime numbers. Additionally, it offers suggestions for interactive courses and tutorials to aid in the learning process.

Uploaded by

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

Python For Beginners 1

This document serves as a beginner's guide to learning Python, highlighting its ease of use, installation, and learning resources. It emphasizes Python's popularity, versatility in applications, and provides a simple example of checking for prime numbers. Additionally, it offers suggestions for interactive courses and tutorials to aid in the learning process.

Uploaded by

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

Python For Beginners

Welcome! Are you completely new to prograrnrning? If not then we presume you will be
looking for information about why and how to get started with Python. Fortunately an
pick
experienced programmer in any prograrnming language (whatever it may be) can
up Python very quickly. It's also easy for beginners to use and learn, so jump in!

Installing
distributions
Installing Python is generally easy, and nowadays many Linux and UNIX
include a recent Python. Even some Windows computers (notably those from HP) now
confi
come with Python already installed. If you do need to install Python and aren't
dent about the task you can find a few notes on the BeginnersGuide/Download wiki
page, but installation is unremarkable on most platforms.

Learning
tai
Before getting started, you may want to find out which IDEs and text editors are
lored to make Python editing easy, browse the list of introductory books, or look at
code samples that you might find helpful.

There is a list of tutorials suitable for experienced programmers on the


BeginnersGuide/Tutorials page. There is also a list of resources in other languages

which might be useful if English is not your first language.


The online documentation is your first port of call for definitive information. There is a

fairly brief tutorial that gives you basic information about the language and gets you
started. You can follow this by looking at the library reference for a full description of
Python's many libraries and the language reference for a complete (though somewhat
dry)explanation of Python's syntax. If youare looking for common Python recipes and
patterns, you can browse the ActiveState Python Cookbook

Looking for Something Specific?


If you want to know whether a particular application, or a library with particular func
tionality, is available in Python there are a number of possible sources of information.
The Python web site provides a Python Package Index (also known as the Cheese Shop.

areference to the Monty Python script of that name). There is also asearch page for a
numberof sources of Python-related information. Failing that, just Google for a phrase
including the word "python'" and you may well get the result you need. If all else fails,
askon the python newsgroup and there's agood chance someone will put you on the

right track.
About Python Programming
" Free and open-source -You can freely use and distribute Python, even for
commercial use.

. Easy to learn -Python has a very simple and elegant syntax. It's much easier
to read and write Python programs compared to other languages like C+t,
Java, C#.

" Portable- Youcan move Python programs from one platform toanother, and
run it without any changes.

Why Learn Python?


Python is easy to learn. Its syntax is easy and code is very readable.
"Python has a lot of applications. It's used for developing web applications,
data science, rapid application development, and so on.
" Python allows youto write programs in fewer lines of code than most of the
programming languages.

The popularity of Python is growing rapidly. Now it's one of the most popular
programming languages.

How to learn Python?


" Interactive Python Course - Want to learn Python by solving quizzes and
challenges after learning each concept? Enroll in our Python Interactive
Course for FREE.

. Python tutorial from Programiz -We provide step by step Python tutorials,
examples, and references. Get started with Python.
. OfficialPython tutorial -Might be hard to follow and understand for
beginners.Visit the official Python tutorial.
Example : Using a flag variable
# Program to check if a number is prime or not

num = 29

# To take input from the user


num = int(input("Enter a number: "))
#define a flag variable
flag = False

if num 1
print (nu, "is not a prime number")
elif num > 1:
heck for factors
for i in range(2, num):
if (nun % i) s 0:
# if factor is found, set flag to True
flag True
# break out of loop
break

check 1f flag is True


if flag
Print (nUm, "is not a prime number")
else
Printnum, "is a prime number")

Run Code »
Output

29 is a prime number

In this program, we have checked if num is prime or not. Numbers less than or
equalto 1are not prime numbers. Hence, we only proceed if the num is greater
than 1.

We check if num is exactly divisible by any number from 2 to num -1.If we


find a factor in that range, the number is not prime, so we set flag to True
and break out of the loop.

Outside the loop, we check if flag is True or False.

" If it is True, num is not aprime number.

" If it is False, num is a prime number.

Note: We can improve our program by decreasing the range of numbers


where we look for factors.

In the above program, our search range is from 2 to num - 1.

We could have used the range, range(2, num//2 ) or


range(2, math. fl0or (math.sqrt(num)+1))The latter range is based on the
fact thatacomposite number must have afactor less than or equal to
the square root of that number. Otherwise, the number is prime.

You can change the value of variable num in the above source code to check
whether a number is prime or not for other integers.

In Python, we can also use the for...else statement to do this task without
using an additional flag variable.

You might also like