Learning Python from C

A little syntax of Python from C to be easy your life in this path :)

Ascci numbers: ‘a’ => ord(‘a’)
Printf -> Print so %c => {:c} , end=””(not \n)
logic operators: || => or
&& => and
syntax: tab => 4 espacios

betty => pep8

Print

If you want to print “\n”

print(r “hola\n”) = hola\n = c:\name (desabilitar el salto de linea)
also you can use 3x ‘ -> print(“‘ sdf “”)
print(“‘ hola
que tal “‘) = hola
que tal

Math

potencia: => **
división / => decimales
división enteros // => enteros

Loop:

for i in range(a,b): #Loop between a(include) to b(not include)#Ways to run a loop in an argvfrom sys import argv
for i in range(0, len(argv)): #if you want to print -> argv[i]
import sys
for i in sys.argv[1:]: #if you want to print -> i
from sys import argv
for i in argv[1:]: #Loop since argv(1) #if you want to print -> i

for i in range(a:b):

Import:

2 ways:

import sys

from + import +

from calculator_1 import add, mul, sub, div
from calculator_1 import *

Main:

# stuff to run always here such as class/def
def main():
pass
# stuff only to run when not called via 'import' here
if __name__ == “__main__”:

Command Line Arguments

You can use these 3 modules: sys, get opt, arg parse

Example using sys:

import sysprint(sys.argv)

And how you can have the argc?

argc = len(sys.argv) -1

Error Output Redirection

Also module sys has “write” and “stdin, stdout, stderr” . Useful for warnings and error message

sys.stderr.write(‘warning, etc\n’)

For terminate

script -> sys.exit().

If you are in this line is because you are really interested in learning Python, you also can collaborate in this publish, let me know what else we could add to this post? ;)

Software engineer in progress