Python Introduction

Python Introduction



PYTHON PROGRAMMING


INTRODUCTION

Python is an object-oriented programming language created by Guido Rossum in 1989. It is ideally designed for rapid prototyping of complex applications.It has interfaces to many OS system calls and libraries and is extensible to C or C++. The benefits of pythons are that it is simple and easy, portable, extensible, build-in data structure and it is an open source
Python is widely used in Artificial Intelligence, Natural Language Generation, Neural Networks and other advanced fields of Computer Science. Python had deep focus on code readability & this class will teach you python from basics.

Python is a programming language with objects, modules, threads, exceptions and automatic memory management.


Python language

Python language is an interpreted language. Python program runs directly from the source code. It converts the source code that is written by the programmer into an intermediate language, which is again translated into machine language that has to be executed.


How memory is managed in Python?


MEMORY MANAGED IN PYTHON

Python memory is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have an access to this private heap and interpreter takes care of this Python private heap.

The allocation of Python heap space for Python objects is done by Python memory manager. The core API gives access to some tools for the programmer to code.

Python also have an inbuilt garbage collector, which recycle all the unused memory and frees the memory and makes it available to the heap space.


What is module and package in Python?
MODULE AND PACKAGE IN PYTHON


In Python, module is the way to structure program. Each Python program file is a module, which imports other modules like objects and attributes.

The folder of Python program is a package of modules. A package can have modules or subfolders.

Mention what are the rules for local and global variables in Python?



Local variables: If a variable is assigned a new value anywhere within the function's body, it's assumed to be local.

Global variables: Those variables that are only referenced inside a function are implicitly global.





Explain database connection in Python Flask?
PYTHON FLASK

Flask supports database powered application (RDBS). Such system requires creating a schema, which requires piping the shema.sql file into a sqlite3 command. So you need to install sqlite3 command in order to create or initiate the database in Flask.

Flask allows to request database in three ways
  • Before_request() : They are called before a request and pass no arguments
  • After_request() : They are called after a request and pass the response that will be sent to the client
  • Teardown_request(): They are called in situation when exception is raised, and response are not guaranteed. They are called after the response been constructed. They are not allowed to modify the request, and their values are ignored.

 Mention five benefits of using Python?

  • Python comprises of a huge standard library for most Internet platforms like Email, HTML, etc.

  • Python does not require explicit memory management as the interpreter itself allocates the memory to new variables and free them automatically

  • Provide easy readability due to use of square brackets

  • Easy-to-learn for beginners

Having the built-in data types saves programming time and effort from declaring variables



Hello World in Python



print "hello world"
Open Terminal And Create a file hello.py and write the above command. Then run the command to execute the program.
python hello.py 

0 comments:

Post a Comment