pyphon using code example

Example 1: how to get started with python

#the best way to start with anything is not to rush and start with the basics
#python however is really good for begginers as it is easy to read and understaned
#and has relatively easy syntax so dont spend a lot of time on the basics like
#print() and if  rather learn the basics and learn about the libraries 
#and a good way to learn about the libraries is https://pypi.org/ if you are also
#struggling to find motivation for programming the best way to work around it is
#to learn how dopamine works in your brain and how to use it in progoramming
#for that use the video https://www.youtube.com/watch?v=9QiE-M1LrZk
#for a good IDE i reccomend pycharm
#and remember programming is not something you should remember to be good 
#programming is something you need to understand and to be a good programmer you 
# need to know how to put the internet to a good use and to know where to search

#if this helped leave it an upvote 
#rubel1130 :)

Example 2: with statement in python

In python if you want to operate some file then you have to use some specific function for that after using that we can read or manipulates the data of the file.
And for operating the file we use open() function. open returns the file object, from which we can access functions and attributes for performing file operation by opening the file.

In the normal file operation we have to follow some rules, like opening the file using 'open()' method then read the file data using 'read()' method after that print the data of file and when all operation gets over we need to close the file using 'close()' method.
Example:
file = open('abc.txt')
data = file.read()
print data
file.close() #file closing is must or it will throw error

Using with statement we can get automatic exception handelling and better syntax.
at the end there is no need of write closing of file it automatically get space cleared by with statement.
Example:
with open('abc.txt') as file: # refer file as object for file object
data = file.read()
print data

or 
 file.write('Hello python')

you can check we not included file close method in the with statement program.
Done!!!

Tags:

Misc Example