Some notes to learn python (Basics: Part one)

Syntax

#To write “Hello, World!” in the command line:

#type “python” then : print (“Hello World”);

#to exist type :exit()


DocStrings

# Docsting is an extendes documentation capability=> it’a a comment

# using a triple quotes at the beginning and end of the doctsting.

DocStirng on python

Vaiables

# A variable is created when u assign a value to it.

#No need to be declared with any particular type it can change type after have been set.

#name varaible can belongs to ([A-z][0–9][_]) and must start with letter or underscores. “Variable name are case-sentive”.

# print statment can be used to output variables

# “+” can be used to combine text and var or even 2 var.

# Combine a number with string lead to an error.


Python Numbers

# 3 numeric type

#int : 1 , 35655555554887711 , -3255522

#float 2.8 , -32.59 , 3.0 , 37e3 , 24E4 , -87.7e100

#complex 2j , 3+5j

# type() fucntion to verify the type of the object


Python Casting

# if we want to specify the type of the varibale we use casting.

# because is an OO language so it use classes to define types. the cast is done by using constructor functions.

# int() to cast to integer

# float () to cast to float

# str() to cast to string


String

# Surounded by either single qotation marks, or double quotation marks

# it can be output to screen using print funcion

#String is an array of bytes representing unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.

#Substring

#strip() methode to remove any whitespace from the beginig or the end.

#len() to return the length of the string

#lower() return the string in lower case

#upper() returns the string in upper case

#replace() replaces a string with another string

#split() splits the string to substr. Should define the instances of the separator:

Command-line String Input

# to Ask user for input we can use input() methode

Operators

check link it’s more useful : operators

Reference

W3School: Python

Like what you read? Give Taklit Zina a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.