Python Intro

I have been working with Python and spent many hours of study, but best way to learn is to teach 🙂

As per my other guides into PHP, Perl, etc .. I will gradually write some intro, intermediate and advanced topics.

As a quick warm up 🙂

$ python -c 'print("Hi World")'
Hi World

$ python -c 'print(type("test"))'
<type 'str'>

$ python -c 'print(3**7)'
2187

Quick bit of OO – defining method

class Car:      # class attrib     category = "Vehicle"      # instance attrib     def __init__(self,name,make,model):         self.name=name         self.make=make         self.model=model      # instance method     def desc(self):         return "Name: {} is made by {} and is the {} body shape".format(self.name,self.make,self.model)

Then creating an object from this class and calling methods

fordLaser=Car("Ford Laser","Ford","Hatchback")
print(fordLaser.desc())

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *