1 / 33

python

Description python 1

Download Presentation

python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PYTHON M.NOUF S.BARAFAH

  2. 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!

  3. 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

  4. BLOCK COMMENT. Block Comment.

  5. INLINE COMMENT. Example print("Hello, World!") #This is a comment EFFICITUR ALIQUAM

  6. 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!

  7. 2) OR """?THIS IS A COMMENT?WRITTEN IN ?MORE THAN JUST ONE LINE?"""?PRINT("HELLO, WORLD!") EFFICITUR ALIQUAM

  8. 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.

  9. FUSCE PRETIUM LIBERO UT MOLESTIE ELEIFEND. ETIAM ANTE EST, ULTRICIES UT METUS NON ULLAMCORPER POSUERE ORCI, QUISQUE IN MOLLIS ELIT. EFFICITUR ALIQUAM

  10. 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

  11. 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:

  12. 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

  13. PYTHON - OUTPUT VARIABLES the Python print( ) function is often used to output variables. Example:X= "Python is awesome"? print(x)

  14. 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

  15. 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

  16. GETTING THE DATA TYPE YOU CAN GET THE DATA TYPE OF ANY OBJECT BY USING THE TYPE ( ) FUNCTION: X = 5 PRINT ( TYPE(X) )

  17. 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

  18. 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

  19. 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))

  20. 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)

  21. 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

  22. 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)

  23. 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

  24. OPERATOR PRECEDENCE:- ( ) ** +X -X ~X * / // % + - << >> & ^ | == != > >= < <= NOT AND OR

  25. 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]

  26. type() From Python's perspective, lists are defined as objects with the data type 'list': MYLIST = ["APPLE", "BANANA", "CHERRY"] PRINT(TYPE(MYLIST)) <CLASS 'LIST'>

  27. 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'}

  28. myset = {"apple", "banana", "cherry"} print(type(myset)) <CLASS 'SET'>

  29. 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)

  30. FUSCE PRETIUM LIBERO UT MOLESTIE ELEIFEND. ETIAM ANTE EST, ULTRICIES UT METUS NON ULLAMCORPER POSUERE ORCI, QUISQUE IN MOLLIS ELIT. EFFICITUR ALIQUAM

  31. EXERCISE: CHANGE THE "YEAR" VALUE FROM 1964 TO 2020. EFFICITUR ALIQUAM

  32. EXERCISE: ADD THE KEY/VALUE PAIR "COLOR" : "RED" TO THE CAR DICTIONARY. EFFICITUR ALIQUAM

  33. THANKS

More Related