E N D
PYTHON M.NOUF S.BARAFAH
PYTHON SYNTAX by creating a python file on the server, using the .py file extension, and running it in the Command Line: print("Hello, World!")? Hello, World!
PYTHON COMMENTS make the code more readable.Comments can be used to prevent execution when testing code. Comments can be used to explain Python code.Comments can be used to Qualification: Graduation or Diploma in the required domain If you think you've got the required skill set, send your resumes to careers@creativedesign.com Last Date: April 07, 2016 Only shortlisted candidates will be called for the test/interview
BLOCK COMMENT. Block Comment.
INLINE COMMENT. Example print("Hello, World!") #This is a comment EFFICITUR ALIQUAM
MULTILINE COMMENTS:- 1) Python does not really have a syntax for multiline comments.To add a multiline comment you could insert a # for each line: Example #first comment. #second comment. ?# third comment. print("Hello, World!”) HELLO, WORLD!
2) OR """?THIS IS A COMMENT?WRITTEN IN ?MORE THAN JUST ONE LINE?"""?PRINT("HELLO, WORLD!") EFFICITUR ALIQUAM
PYTHON VARIABLES A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables: A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables) A variable name cannot be any of the Python keywords.
FUSCE PRETIUM LIBERO UT MOLESTIE ELEIFEND. ETIAM ANTE EST, ULTRICIES UT METUS NON ULLAMCORPER POSUERE ORCI, QUISQUE IN MOLLIS ELIT. EFFICITUR ALIQUAM
EXAMPLE MYVAR = "JOHN" MY_VAR = "JOHN" _MY_VAR = "JOHN" MYVAR = "JOHN" MYVAR = "JOHN" MYVAR2 = "JOHN" PRINT(MYVAR) PRINT(MY_VAR) PRINT(_MY_VAR) PRINT(MYVAR) PRINT(MYVAR) PRINT(MYVAR2) OUT PUT
X, Y, Z = "ORANGE", "BANANA", "CHERRY" PRINT(X) PRINT(Y) PRINT(Z) Many Values to Multiple Variables Python allows you to assign values to multiple variables in one line:
ONE VALUE TO MULTIPLE VARIABLES AND YOU CAN ASSIGN THE SAME VALUE TO MULTIPLE VARIABLES IN ONE LINE: X = Y = Z = "ORANGE" PRINT(X) PRINT(Y) PRINT(Z) ORANGE
PYTHON - OUTPUT VARIABLES the Python print( ) function is often used to output variables. Example:X= "Python is awesome"? print(x)
X = "PYTHON"? X = 5? Y = "IS"? Y = "JOHN" Z = "AWESOME"? ?PRINT(X + Y) PRINT(X, Y, Z) X = 5? Y = 10? PRINT(X + Y) X = "PYTHON " X = 5? ?Y = "IS " Y = "JOHN"? ?Z = PRINT(X, Y) "AWESOME"?PRINT(X + Y + Z) OUT PUT
PYTHON DATA TYPES Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set Boolean Type: bool None Type: NoneType
GETTING THE DATA TYPE YOU CAN GET THE DATA TYPE OF ANY OBJECT BY USING THE TYPE ( ) FUNCTION: X = 5 PRINT ( TYPE(X) )
EXAMPLE DATA TYPE X = "HELLO WORLD" STR X = 20 INT X = 20.5 FLOAT X = ["APPLE", "BANANA", "CHERRY"] LIST X = ("APPLE", "BANANA", "CHERRY") TUPLE X = {"NAME" : "JOHN", "AGE" : 36} DICT X = {"APPLE", "BANANA", "CHERRY"} SET X = TRUE BOOL X = NONE NONETYPE
x = -20 y = 1 z = 2564856978696 print(type(x)) print(type(y)) print(type(z)) X = 2.20 Z = -10.33 PRINT(TYPE(X)) PRINT(TYPE(Z)) OUTPUT: INT
TYPE CONVERSION X = 10 # INT Y = 1.0 # FLOAT # CONVERT [INT] TO [FLOAT] A = FLOAT(X) PRINT(TYPE(A)) # CONVERT [FLOAT] TO [INT] B = INT(Y) PRINT(TYPE(B))
PYTHON ARITHMETIC OPERATORS OPERATOR EXAMPLE SAME AS + ADDITION X + Y - SUBTRACTION X - Y * MULTIPLICATION X * Y / DIVISION X / Y % MODULUS X % Y ** EXPONENTIATION X ** Y // FLOOR DIVISION X // Y X = 15 Y = 2 PRINT(X // Y)
PYTHON ASSIGNMENT OPERATORS:- OPERATOR EXAMPLE SAME AS = X = 5 X = 5 += X += 3 X = X + 3 -= X -= 3 X = X - 3 *= X *= 3 X = X * 3 /= X /= 3 X = X / 3 %= X %= 3 X = X % 3 //= X //= 3 X = X // 3 **= X **= 3 X = X ** 3 >>= X >>= 3 X = X >> 3 <<= X <<= 3 X = X << 3
PYTHON COMPARISON OPERATORS:- OPERATOR NAME EXAMPLE == EQUAL X == Y != NOT EQUAL X != Y > GREATER THAN X > Y < LESS THAN X < Y >= GREATER THAN OR EQUAL TO X >= Y <= LESS THAN OR EQUAL TO X <= Y X = 5 Y = 3 TRUE PRINT(X >= Y)
PYTHON LOGICAL OPERATORS:- Operator Description Example and Returns True if both statements are true x < 5 and x < 10 or Returns True if one of the statements is true x < 5 or x < 4 not Reverse the result, returns False if the result is true not(x < 5 and x < 10) x = 5 print(not(x > 3 and x < 10)) False
OPERATOR PRECEDENCE:- ( ) ** +X -X ~X * / // % + - << >> & ^ | == != > >= < <= NOT AND OR
PYTHON LISTS thislist = ["apple", "banana", "cherry"] ?print(thislist) list1 = ["apple", "banana", "cherry"] list2 = [1, 5, 7, 9, 3] list3 = [True, False, False] print(list1) print(list2) print(list3) ['APPLE', 'BANANA', 'CHERRY'] [1, 5, 7, 9, 3] [TRUE, FALSE, FALSE]
type() From Python's perspective, lists are defined as objects with the data type 'list': MYLIST = ["APPLE", "BANANA", "CHERRY"] PRINT(TYPE(MYLIST)) <CLASS 'LIST'>
PYTHON SETS We are looking for innovative and result oriented individuals for the position. A professional with advanced knowledge in Adobe Illustrator/Coral Draw, Adobe Photoshop with highly creative skills and 2 years working experience in the similar capacity. thisset = {"apple", "banana", "cherry"}print(thisset) {'BANANA', 'APPLE', 'CHERRY'}
myset = {"apple", "banana", "cherry"} print(type(myset)) <CLASS 'SET'>
PYTHON DICTIONARIES A dictionary is a collection which is ordered*, changeable and do not allow duplicates. Dictionaries are used to store data values in key:value pairs. THISDICT = {? "BRAND": "FORD",? "MODEL": "MUSTANG",? "YEAR": 1964 ?} PRINT(THISDICT)
FUSCE PRETIUM LIBERO UT MOLESTIE ELEIFEND. ETIAM ANTE EST, ULTRICIES UT METUS NON ULLAMCORPER POSUERE ORCI, QUISQUE IN MOLLIS ELIT. EFFICITUR ALIQUAM
EXERCISE: CHANGE THE "YEAR" VALUE FROM 1964 TO 2020. EFFICITUR ALIQUAM
EXERCISE: ADD THE KEY/VALUE PAIR "COLOR" : "RED" TO THE CAR DICTIONARY. EFFICITUR ALIQUAM