Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Thursday, 17 May 2018

Chaudhari Karan

Python basic syntax

By     2 comments:

Python Basic Syntax

Hello friends, In this lecture, we will discuss python basic syntax.

The Python language is very similarities to C, Perl, and Java. But some definite differences between the languages.

Programming  mode:


There are two types of programming mode in python.
  • ·         Interactive programming mode
  • ·         Script programming mode

Interactive programming:

In interactive programming mode invoking the interpreter without passing parameter script file and following python prompt will brings up.

Python basic syntax

Type following text at python prompt and press the Enter. Following result shows.
But if you using older version python like python 2.4 something, so then use print keyword then show the result.

Python basic syntax

Script programming:

In script programming mode invoking the interpreter with parameter script file. Python has .py extension.
First, create the new file and save the file with  .py extension. Then run the program. It would be run in the python shell.

Python Identifier:

Python identifier is the name. For identify any class, method, function, variable, module or objects python identifier used.
The identifier is starting from A to Z, or a to z, underscore and digits o to 9.
Punctuation character like @,$, and % does not allow in python within the identifier.
Python language is case sensitive programming language. So if pass identifier like Car and car are two different identifiers.

Naming conventional for python identifier:

  • ·         The class name always starts with an uppercase letter. And all other identifiers start with lowercase letter.
  • ·         Identifier starting with the single underscore it is indicated identifier is private.
  • ·         Identifier starting with the double underscore it is indicated identifier is strongly private.
  • ·         The identifier also ending with two trailing underscore.

Reserved Words:

Here is the list of the keywords in python. These keywords are reserved words. Keywords cannot use as constant, variable, and any other identifier name. All words are in the lowercase letter.
and
assert
break
class
continue
def
del
elif
else
except
Exec
finally
for
from
global
If
import
in
Is
lambda
Not
or
pass
print
raise
Return
try
while
with
yield

Lines and Indentation:

Python does not provide braces to indicate blocks of code for the class and define the function. So in python block are denoted by lines indentation, it is rigidly enforced.
Example:

Python basic syntax

 Multi-line Statement:

In python statement end with the new line. Python allows the use of line continuation character(\).
Example :
Python basic syntax

Multi-line can contain with [] or {}.
Example:
Python basic syntax

Comments in Python:

In python, comments are denoted by hash sign #.
Example :
Python basic syntax


You can comment on the same line after the statement.
Example:
Python basic syntax


You can comment multi-line comment as shown in the example.
Example:
Python basic syntax

Quotation in python:

Python support single(‘ '), double("  " ), or triple(‘''  ‘'')("""  """) quotes to denote String. Quotes start and end with same quote.
Example:
Python basic syntax

 Blank lines:

Lines contain whitespace, possible with the comment. It is known as blank lines. Python is ignoring the blank lines.

Multiple statements on a Single Line:

In single line for allowing multiple statements use the semicolon ;
Example:
Python basic syntax

Multiple statements Groups as suites:

A group of individual statements, which make a single code block is called suites in Python. The compound or complex statements, such as if, while, def, and class requires a header line and a suite.
Header lines start the statement with the keyword and terminate with a colon: and are followed by one or more lines which make up the suite.
 Example:
Python basic syntax


Next: In the next lecture we will discuss python variable types.


 




Read More

Tuesday, 15 May 2018

Chaudhari Karan

Python Introduction and how to install python

By     1 comment:

Lecture 1 Python Introduction and how to install python:

Hello  Friends,  In this lecture, we will discuss introduction of python and how to install python.


Python Introduction


Python language is interactive, interpreted, high-level, and object-oriented scripting language.

It uses English keyword frequently whereas other language uses punctuation. Python language has fewer syntactical constructions than other languages. Python is designed for highly readable.
  • ·         Python Interactive:  Python prompt is interpreter directly interact with program.
  • ·         Python Interpreted: Python language is processed at runtime by the interpreter. So you do not need to compile for your program before executing it. It is similar to PHP and PERL language.
  • ·         Python Object-oriented:  Python is object-oriented programming language which is support object-oriented style and technique of programming that encapsulates code within objects.
  • ·         Python Beginner's language:  Python is very easy and greatest language. It supports the development of the wide range of applications from simple text processing to WWW browsers to games.

Python Feature:


Here are some python features.
  • ·         Easy to learn: Python language is very easy to learn. It has some structure, few keywords, and clearly defined syntax. Which make the language very easy.
  • ·         Easy to read: Python code is clearly defined.
  • ·         Easy to maintain: Python source code is fairly easy to maintain.
  • ·         Interactive mode: Python support interactive mode it allows debugging and interactive testing of snippets of code.
  • ·         Standard library: Python has a bulk of library which is the standard library. It is very portable and its run on each platform like Window, Unix, and Macintosh.
  • ·         Portable: Python has interface in all platform.
  • ·         GUI programming: Python support GUI(Graphical User Interface) application. It created and ported to many other system calls, libraries, and window system.

Apart from that python has some big list of good feature.

Python support Structured and functional programming methods as well as OOP.
  • ·         It is to provide high-level dynamic data types and support checking of that dynamic data types.
  • ·         It used a scripting language or compiled to byte-code for building large applications.
  • ·         It is supports automatic garbage collection.
  • ·         It easily integrated with C, C++, Java, COM, CORBA, and Active X.

Python Environment:


Python is available in different platform Linux, Windows, and Mac OS X. Now, understand how to setup the python environment.

Local Environment Setup:


Open the Terminal Window and type "python" and find out if it is installed and which python version is installed.
  • ·         Unix Solaris, Linux, FreeBSD, AIX,HP/UX, SunOS, IRIX, etc.
  • ·         Win 9X/NT/2000
  • ·         Macintosh Intel, PPC, 68KIntel, PPC, 68K
  • ·         OS/2
  • ·         DOS multiple versions
  • ·         PalmOS
  • ·         Nokia mobile phones
  • ·         Windows CE
  • ·         Acorn/RISC OS
  • ·         BeOS
  • ·         VMS/OpenVMS
  • ·         QNX
  • ·         Amiga
  • ·         VxWorks
  • ·         Psion
  • ·         Python has also been ported to the .NET virtual machines and java

How to download python:


For download python, you can download it from python official site. CLICK HERE TO DOWNLOAD

You can download python documentation CLICK HERE. Which is available in HTML, PDF, and PostScript formats.

How to install python:


Python is available for the wide variety of platform. So you need to download applicable binary code for your platform.

If suppose binary code is not available for your platform, so you need to a C compiler to compile the source code. Compiling the source code that needs for your platform installation.

Windows Installation:

  • ·         Open your web browser and go to https://www.python.org/downloads/.
  • ·         Click on the link for windows installer python-ABC.msi file, where ABC is version need for your install.
  • ·         To use installer python-ABC.msi, Windows system support Microsoft Installer 2.0.
  • ·         Save installer file to your local machine and then run it to find out if your machine supports MSI.
  • ·         Run that downloaded file, then python install wizard open which is ready to use. After accept setting and wait until the install is finished. Then your python is ready to use.

Unix and Linux Installation:


Here are the simple steps to install Python on Unix/Linux machine.
  • ·         Open your web browser and go to https://www.python.org/downloads/.
  • ·         Click on the link for download zipped source code. Which is available for Unix/Linux.
  • ·         Then download and extract files.
  • ·         Editing the Modules/Setup file if you want to customize some options.
  • ·         run ./configure script
  • ·         then make install

This installs Python at standard location /usr/local/bin and python libraries at /usr/local/lib/pythonXXwhere XX is the version of Python.

Macintosh Installation


  • ·         See link http://www.python.org/download/mac/ for instructions on getting the current version along with extra tools to support development on the Mac.
  • ·         Python for older Mac OS's before Mac OS X 10.3 which is released in 2003, Mac Python is available.
  • ·         Jack Jansen maintains it and you can have full access to the entire documentation at his website − http://www.cwi.nl/~jack/macpython.html. You can find complete installation details for Mac OS installation.

Next: In next lecture, we will discuss basic syntax of python.

Read More