Tuesday, February 26, 2019

Python Variables

Creating Variables:

Unlike other programming languages, Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.

Example

x = 10  # x is a int type variabe 
y = "Python" # y is the string type variable
print(x)
print(y)


Variable Names

A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables:
  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive (age, Age and AGE are three different variables)
  • Remember that variables are case-sensitive  

Q1:-Write a Python Program takes two number and sum that

Program:

x = int(input("Enter first number:")# input method return a string 
y = int(input("Enter second Number:") # for type casting use int(),float()
print(x + y)



Monday, February 4, 2019

Get started with python (install python interpreter)

Python is available on a wide variety of platforms including Linux and Mac OS X. Let's understand how to set up our Python environment.

Getting Python

The most up-to-date and current source code, binaries, documentation, news, etc., is available on the official website of Python https://www.python.org/
You can download Python documentation from https://www.python.org/doc/. The documentation is available in HTML, PDF, and PostScript formats.

Windows Installation

Here are the steps to install Python on Windows machine.
  • Open a Web browser and go to https://www.python.org/downloads/.
  • Follow the link for the Windows installer python3.6.exe file where is the version you need to install.
  •  the Windows system must support Microsoft Installer 2.0. Save the installer file to your local machine and then run it to find out if your machine supports EXE.
Run the downloaded file. This brings up the Python install wizard, which is really easy to use. Just accept the default settings, wait until the install is finished, and you are done.

pycharm IDE


Pycharm IDE provide the help to learn python (provide autocomplete syntax)
and download the pycharm ide :https://www.jetbrains.com/pycharm/download/


Setting up PATH

Programs and other executable files can be in many directories, so operating systems provide a search path that lists the directories that the OS searches for executables.
The path is stored in an environment variable, which is a named string maintained by the operating system. This variable contains information available to the command shell and other programs.
The path variable is named as PATH in Unix or Path in Windows (Unix is case sensitive; Windows is not).
In Mac OS, the installer handles the path details. To invoke the Python interpreter from any particular directory, you must add the Python directory to your path.
Step1: go to the python directory

Step2: go to the python directory:C:\Users\amankumar\AppData\Local\Programs\Python\Python36-32\Scripts
Step3:copy the address of following directery open the following setting
go to computer >press the right mouse key and go to properties>
click the Advance system setting> click on Environment Variables>

>create a new variable give Name and path pest your directory


check for set the path :
step1:open command promt(cmd)
step2:type python and press Enter key and start your python interpreter





if you comes problems setting the Path you comment 


Introduction to python language

Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales. Van Rossum led the language community until stepping down as leader in July 2018.
It is used for:
  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.

What can Python do?

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files.
  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used for rapid prototyping, or for production-ready software development.

Why Python?

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
  • Python has a simple syntax similar to the English language.
  • Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
  • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.
  • Python can be treated in a procedural way, an object-orientated way or a functional way.

Good to know

  • The most recent major version of Python is Python 3, which we shall be using in this tutorial. However, Python 2, although not being updated with anything other than security updates, is still quite popular.
  • In this tutorial Python will be written in a text editor. It is possible to write Python in an Integrated Development Environment, such as Thonny, Pycharm, Netbeans or Eclipse which are particularly useful when managing larger collections of Python files.

Python Syntax compared to other programming languages

  • Python was designed to for readability, and has some similarities to the English language with influence from mathematics.
  • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
  • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.