Beruflich Dokumente
Kultur Dokumente
PHYSICS LAB
MEHAK & AVIJIT-(8620967459,7685817762)
Programming Languages:
A programming language is a vocabulary and set of grammatical rules for
instructing a computer or computing device to perform specific tasks. The
term programming language usually refers to
high-level languages, such
as BASIC, C, C++, COBOL, Java,FORTRA
N, Ada, and Pascal.
What is Python?
Python is an interpreted high-level programming
language for general-purpose programming. Created by Guido
van Rossum and first released in 1991, Python has a design philosophy that
emphasizes code readability, notably using significant whitespace.
Python is meant to be an easily readable language. Its formatting is visually
uncluttered, and it often uses English keywords where other languages use
punctuation. Unlike many other languages, it does not use curly brackets to
delimit blocks, and semicolons after statements are optional.
Reference implementation:
CPython is the reference implementation of Python. It is written in C, meeting
the C89 standard with several select C99 features. It compiles Python programs into an
intermediate bytecode which is then executed by its virtual machine. CPython is
distributed with a large standard library written in a mixture of C and native Python. It is
available for many platforms, including Windows and most modern Unix-like systems.
Platform portability was one of its earliest priorities.
Other implementations:
PyPy is a fast, compliant interpreter of Python 2.7 and 3.5. Its just-in-time
compiler brings a significant speed improvement over CPython.
Interesting fact: Python is named after the comedy television show Monty
Python’s Flying Circus. It is not named after the Python snake.
Easy to Learn: Learning python is easy as this is a expressive and high level
programming language, which means it is easy to understand the language and
thus easy to learn.
Cross platform: Python is available and can run on various operating systems
such as Mac, Windows, Linux, Unix etc. This makes it a cross platform and
portable language.+
Large standard library: Python comes with a large standard library that has
some handy codes and functions which we can use while writing code in Python.
Free: Python is free to download and use. This means you can download it for
free and use it in your application.
Supports exception handling: If you are new, you may wonder what is an
exception? An exception is an event that can occur during program exception and
can disrupt the normal flow of program. Python supports exception handling
which means we can write less error prone code and can test various scenarios
that can cause an exception later on.
If you are new to programming then you may be wondering what do we mean by
IDE? IDE stands for integrated development environment. It is a software that
consolidates the basic tools that are required to write and test programs in a
certain language. Typically, an IDE contains a code editor, a compiler or
interpreter and a debugger that you can access at the same place through IDE
GUI.
Interactive Mode
When commands are read from a tty, the interpreter is said to be in interactive
mode. In this mode it prompts for the next command with the primary prompt,
usually three greater-than signs (>>>); for continuation lines it prompts with the
secondary prompt, by default three dots (...). The interpreter prints a welcome
message stating its version number and a copyright notice before printing the first
prompt:
A.M.PHYSICS LAB
MEHAK & AVIJIT-(8620967459,7685817762)
>>> the_world_is_flat = 1
>>> if the_world_is_flat:
...
>>> 50 - 5*6
20
5.0
>>> 8 / 5.0
1.6
The integer numbers (e.g. 2, 4, 20) have type int, the ones with a fractional part
(e.g. 5.0, 1.6) have type float. We will see more about numeric types later in the
tutorial.
The return type of a division (/) operation depends on its operands. If both
operands are of type int, floor division is performed and an int is returned. If either
operand is a float, classic division is performed and a float is returned. The //
operator is also provided for doing floor division no matter what the operands are.
The remainder can be calculated with the % operator:
>>> 17 / 3 # int / int -> int
5.666666666666667
5.0
17
25
128
The equal sign (=) is used to assign a value to a variable. Afterwards, no result is
displayed before the next interactive prompt:
>>> width = 20
>>> height = 5 * 9
900
If a variable is not “defined” (assigned a value), trying to use it will give you an
error:
There is full support for floating point; operators with mixed type operands convert
the integer operand to floating point:
>>> 3 * 3.75 / 1.5
7.5
>>> 7.0 / 2
3.5
A.M.PHYSICS LAB
MEHAK & AVIJIT-(8620967459,7685817762)
In interactive mode, the last printed expression is assigned to the variable _. This
means that when you are using Python as a desk calculator, it is somewhat easier to
continue calculations, for example:
12.5625
>>> price + _
113.0625
>>> round(_, 2)
113.06
This variable should be treated as read-only by the user. Don’t explicitly assign a
value to it — you would create an independent local variable with the same name
masking the built-in variable with its magic behavior.
In addition to int and float, Python supports other types of numbers, such as
Decimal and Fraction. Python also has built-in support for complex numbers, and
uses the j or J suffix to indicate the imaginary part (e.g. 3+5j).
radians) of x.
acos(…) acos(x) : Return the arc cosine (measured
in radians) of x.
atan(…) atan(x) : Return the arc tangent (measured
in radians) of x.
radians(...) radians(x) :Convert angle x from degrees to
radians.
degrees(…) degrees(x) :Convert angle x from radians to
degrees.
sqrt(…) sqrt(x) : Return the square root of x.
pow(…) pow(x, y) :Return x**y (x to the power of
y).
exp(…) exp(x) :Return e raised to the power of x.
log(…) log(x[, base]) : Return the logarithm of x to
the given base.
If the base not specified, returns the
natural logarithm (base e) of x.
Use all of the above functions in interactive mode with a suitable choice of x.
A.M.PHYSICS LAB
MEHAK & AVIJIT-(8620967459,7685817762)
You are already familiar with two data type, float and integer.Soon you will
become familiar with the other data types in python like
string,list,set,tuple,dictionary etc.
>>> a=2
>>> type(a)
<type 'int'>
>>> b=3.5
>>> type(b)
<type 'float'>
>>> a=[3,5,4,3]
>>> type(a)
<type 'list'>
>>> a="python"
>>> type(a)
<type 'str'>