1 / 10

Python Programming L anguage

Python Programming L anguage. What have we learnt so far?. Variables. What are they used for? Data types. What three data types are there? White space. Why is this important? Statements. How do we write a statement? Comments. How do we write a comment?

carnig
Download Presentation

Python Programming L anguage

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 Programming Language

  2. What have we learnt so far? Variables. What are they used for? Data types. What three data types are there? White space. Why is this important? Statements. How do we write a statement? Comments. How do we write a comment? Arithmetic What are they? operatorsxx There is 6 in total.

  3. Case Sensitivity • You must be careful when you are typing and use the appropriate letter case for the different syntax you are using. • Variables are all in lowercase. spam = 6 • Booleans are title case. bool = True

  4. Strings Strings are typed in between two speech marks. Below is the variable brian that has been assigned the following string. “Always look on the bright side of life”

  5. Escape • If you used double quotes you can get away without using the escape • back slash symbol. Certain character cannot be just typed into a string, they need to be escaped. For example if I’m typing in I’m I need to escape the apostrophe by using the back slash symbol.

  6. Access by Offset Each character in a string has a subscript or offset, which is a fancy way of saying it has a number attached to it. The number starts at 0 for the leftmost character and increases by one as you move character-by-character to the right. Check out the diagram in the editor!

  7. Methods • Methods are pre-built pieces of code that preform certain tasks for us. • Four String Methods are : - • len() This will give us the length of the string. • print len (parrot) • lower() This will convert the string to lowercase • print parrot.lower() • upper() This will convert the string into upercase • print parrot.upper() • str() This will make strings out of non strings • print str(parrot)

  8. Dot Notation… len(string) and str(object) MR SNELL IS BRILLIANT MR SNELL 21 • Why uselen(string) and str(object), but dot notation (e.g."String".upper()) for the rest. • Dot notation works on string literals ("The Ministry of Silly Walks".upper()) and variables assigned to strings (ministry.upper()) because these methods are specific to strings—that is, they don't work on anything else. • best teacher = “Mr Snell is brilliant” • mrsnell is brilliant”.upper() • best teacher.upper() • By contrast, len() and str() can work on a whole bunch of different objects so they aren't tied to strings with dot notation • len (best teacher)

  9. Explicit String Conversion • Str() turns non-strings into strings? The fancy name for that process is explicit string conversion. • You're explicitly telling Python, "Hey, I know this isn't a string, but I want to turn it into one.“ • Making a number into a string can let you glue together strings and numbers (which Python normally won't allow). 

  10. String Formatting • The % string formatter replaces the %s (the "s" is for "string") in our string with the variables in parentheses. • The syntax went like this: • print "%s" % (string_variable) • You can have as many variables (or strings!) separated by commas between your parentheses as you like:

More Related