Python Intro

Python Intro

Python 2 main focal point:

  • Code readability
  • Simplicity

Compile programming language VS Interpreter programming language:

  • Compile your code into an executable file. then execute the binary - Compiled code - file.
  • Run the script instantaneously without compiling into binary. Because when you run python command you're not running python code standalone. I mean the python program compile your code into binary just in time.

Our IDE - Integrated Development Environment

  • VSCode (My preference)
  • PyCharm community edition

Basic types in Python

  1. Number (Integer, Floating point)
  2. String (Anything wrapped between quotations - two/six single/double quote or )
  3. Boolean (True, and False)
  4. List (Arrays can contain different datatypes. e.x. ['A', 12, True])
  5. Dictionary (JSONs with a little different syntax. e.x. {}['name'] = 'Kasir')

Comments in Python

  • Single line (#)
  • Multi line ('''''')

'''
? ? This is a multiline comment due to it has no effect in Python
? ? Because Python ignore multiline strings that are not assigned to a variable
'''

# And I am a single line comment        

functions

We can type our functions - It comes later on


def printList(numbers)
? ? print(numbers)
? ? for number in numbers:
? ? ? ? print(number)
? ? ? ? # print(type(numbers[index]))


def manyArguments(*args):
? ? print(args)
? ? for arg in args:
? ? ? ? print(arg)
? ? ? ? # print(type(numbers[index]))


list1 = [1,2,3,4,5,6]
str1 = 'string'
number1 = 123456
bool1 = True


manyArguments(list1, str1, number1, bool1)
printList(list1):        

classes

class Enemy:
? ? # FIXME: wrong usage
? ? # __init__(self):
? ? #? ? ?anything = 'something'


? ? # FIXME: wrong usage
? ? # def __init__(self):
? ? #? ? ?self.attack_low = self.attack_low
? ? #? ? ?self.attack_high = self.attack_high
? ? def __init__(self, attack_low, attack_high):
? ? ? ? self.attack_low = attack_low
? ? ? ? self.attack_high = attack_high


? ? # README: static property
? ? hp = 200


? ? def get_hp(self):
? ? ? ? return self.hp


? ? def get_attack_info(self):
? ? ? ? print(self.attack_high, self.attack_low)


e1 = Enemy(80, 100)


e1.get_attack_info()
print(e1.get_hp())        

Modules

  • breaking your codebase into modules
  • The __init__.py file lets the Python interpreter know that a directory contains code for a Python module.?
  • __pycache__ is a directory that contains bytecode cache files that are automatically generated by python, namely compiled python, or . pyc , files. You might be wondering why Python, an "interpreted" language, has any compiled files at all.

No alt text provided for this image


要查看或添加评论,请登录

Mohammad Jawad barati的更多文章

  • Write test for nanostores

    Write test for nanostores

    why I wrote this post in the first place? Lack of tut and doc around this awesome library that makes our lives easier…

    1 条评论
  • My very own Linux cheat sheet

    My very own Linux cheat sheet

    HAL: Hardware Abstraction Layer do abstract hardwares for us /sys is where we can see what is connected to the system…

    1 条评论
  • ?????? ???? ?? ?????

    ?????? ???? ?? ?????

    ?? ???? ????: ???? ???? 43 ???? ?? (????? ?? ??????) ?? ??? ???? ???? ? ??????? ?????. ??? ??? ??????? ??? 56 ???? ??…

    2 条评论
  • Angular Material UI

    Angular Material UI

    IMO you need to know 3 things before reading this article: Authentication and Authorization in Angular. Whether you…

  • Create Angular project

    Create Angular project

    First please note that the following instructions are totally biased and is my favorite way of doing it. BTW if you…

  • Learn Angular fundamentals.

    Learn Angular fundamentals.

    Note that I am still a backend developer who is dealing with frontend stuff BTW it is not so hard. IMO Angular is much…

  • NestJS task scheduler

    NestJS task scheduler

    To tackle queue issues in NestJS we use @nestjs/schedule. With this package we can define declarative cron jobs.

  • OTP code in Node.js

    OTP code in Node.js

    Send a time-based OTP code - define TTL for the code Keep the symetric keys very safe Use approved cryptographic…

  • Refresh Token + Logout functionality in Node.js

    Refresh Token + Logout functionality in Node.js

    Here is how I implement refresh token in Node.js.

  • My journey in gPRC

    My journey in gPRC

    I am just fooling around gPRC. Please do not count this article as complete right now.

社区洞察

其他会员也浏览了