Example: stock market

Python Beginner Tutorials

Python Beginner Tutorials - 24th July 2015 View online at Beginner TutorialsBeginnerGetting StartedNumbersString basics String methodsListsTuplesDictionariesDatatype castingIf statementsFunctionsLoopsRandom numbersObjects and classesEncapsulationMethod overloadingInheritancePolymorphismInner classesFactory methodBinary numbersRecursive functionsLoggingSubprocessThreadingTopPa ge 1 Python Beginner Tutorials - 24th July 2015 View online at startedPython is a general-purpose computer programming language, ranked among the topeight most popular programming languages in the can be used to create many things including web applications, desktop applications as scripting interpreter and many do note the online interpreters may not work for everything but will work for thebeginner Python code onlineSkulpt Python interpreter Python Python interpreterCodepad Python inter

Python Beginner Tutorials - 24th July 2015 View online at https://pythonspot.com. Getting started. Python is a general-purpose computer programming language, ranked among the top

Tags:

  Programming, Python, Beginner, Tutorials, Python beginner tutorials

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Python Beginner Tutorials

1 Python Beginner Tutorials - 24th July 2015 View online at Beginner TutorialsBeginnerGetting StartedNumbersString basics String methodsListsTuplesDictionariesDatatype castingIf statementsFunctionsLoopsRandom numbersObjects and classesEncapsulationMethod overloadingInheritancePolymorphismInner classesFactory methodBinary numbersRecursive functionsLoggingSubprocessThreadingTopPa ge 1 Python Beginner Tutorials - 24th July 2015 View online at startedPython is a general-purpose computer programming language, ranked among the topeight most popular programming languages in the can be used to create many things including web applications, desktop applications as scripting interpreter and many do note the online interpreters may not work for everything but will work for thebeginner Python code onlineSkulpt Python interpreter Python Python interpreterCodepad Python interpreterRun Python code on your machineOfficial Python Installation GuidePyCharm IDE (recommended)Try this code:Try this code to test if Python is installed correctly.

2 #!/usr/bin/env pythonprint("Hello World!")print("This is a Python program.")(In Python you do not have to use the brackets around the print function, for Python it required.)Expected output:Hello World!This is a Python programNext tutorialPage 2 Python Beginner Tutorials - 24th July 2015 View online at 3 Python Beginner Tutorials - 24th July 2015 View online at numbersPython supports these data types for numbers:name purposeintwhole numberlonglong integersfloatfloating point real valuescomplexcomplex numbersExample:#!/usr/bin/pythonx = 3 # an integerf = # a floating real pointname = " Python " # a stringbig = 358315791L # long, a very large numberz = complex(2,3) # (2+3i) a complex number.

3 Consists of real and imaginary (x)print(f)print(name)print(big)print(z) (2+3j)To find the maximum values depend on your minimum and maximums on a 32 bit machine:Page 4 Python Beginner Tutorials - 24th July 2015 View online at minimum maximumsigned int-21474836472147483647long limited only by memoryfloat +308 The number range on a 64 bit machine:datatype minimum maximumsigned int-922337203685477580792233720368547758 07long limited only by memoryfloat minimum maximumOperationsYou can do arithemetic operations such as addition (+), multiplication (*), division (/) andsubstractions (-).

4 #!/usr/bin/env pythonx = 3y = 8sum = x + yprint(sum)Expected output: inputYou can also ask the user for input using the raw_input function:#!/usr/bin/env pythonPage 5 Python Beginner Tutorials - 24th July 2015 View online at = int(raw_input("Enter x:"))y = int(raw_input("Enter y:"))sum = x + yprint(sum)In this case we want whole numbers (integers), which is why we write int() around thefunctions. If you want floating point numbers you would write float(raw_input( Enter x: )).In the latest Python version you can use the input() function instead:#!/usr/bin/env pythonx = int(input("Enter x:"))y = int(input("Enter y:"))sum = x + yprint(sum)Next tutorial (Strings) Previous tutorialTopPage 6 Python Beginner Tutorials - 24th July 2015 View online at stringsIf you use Python put brackets around the print Python we can do various operations on strings:#!

5 /usr/bin/pythons = "Hello Python "print s # prints whole stringprint s[0] # prints "H"print s[0:2] # prints "He"print s[2:4] # prints "ll"print s[6:] # prints " Python "print s + ' ' + s # print concatenated ('Hello','Thanks') # print a string with a replaced wordOutput:Hello PythonHHellPythonHello Python Hello PythonThanks PythonPython String compareTo compare two strings we can use the == operator.#!/usr/bin/pythonsentence = "The cat is brown"q = "cat"if q == sentence: print 'equal' else: print 'not equal'Page 7 Python Beginner Tutorials - 24th July 2015 View online at String containsIn Python you can test if a string contains a substring using this code:#!

6 /usr/bin/pythonsentence = "The cat is brown"q = "cat"if q in sentence: print q + " found in " + sentenceNext tutorial (String methods) Previous (numbers)TopPage 8 Python Beginner Tutorials - 24th July 2015 View online at methodsYou learned how to define strings, compare strings and test if the string containssomething in the previous tutorial. In this article you will learn that there are more funthings you can do with of a stringWe can get the length a string using the len() function.#!/usr/bin/env pythons = "Hello world" # define the stringprint len(s) # prints the length of the stringOutput:11 Converting to uppercase or lowercaseThe function upper() can be called to convert a whole string to uppercase.

7 #!/usr/bin/env pythons = " Python " # define the strings = () # convert string to uppercaseprint s # prints the stringOutput:PYTHONL ikewise we can convert a string to lower characters using the lower() strings together (concatinating)We can add strings together use the plus operator:Page 9 Python Beginner Tutorials - 24th July 2015 View online at #!/usr/bin/env pythonstr1 = " Python "str2 = " is my favorite programming language."print str1 + str2 # print a concatenated : Python is my favorite programming in stringsIn Python there are special characers that you can use in a string.

8 You can use them tocreate newlines, tabs and so on. Let s do example,we will use the \n or newlinecharacter:#!/usr/bin/env pythonstr1 = "In Python ,\nyou can use special characters in strings.\nThese special characters can "print str1 Output:In Python ,you can use special characters in special characters can in stringsSometimes you may want to show double quotes in the string, but because they arealready used to start or end a string we have to escape them. An example:#!/usr/bin/env pythonPage 10 Python Beginner Tutorials - 24th July 2015 View online at = "The word \"computer\" will be in quotes.

9 "print str1 Output:The word "computer" will be in characters overviewAn overview of special characters that you can use in strings:Action characterNewline \nQuotes \ Single quote \ Tab \tBackslash \\Next tutorial: Lists Previous (strings) TopPage 11 Python Beginner Tutorials - 24th July 2015 View online at listsListsA list can be used as:#!/usr/bin/pythonl = [ "Drake", "Derp", "Derek", "Dominique" ]print l # prints all elementsprint l[0] # print first elementprint l[1] # prints second elementOutput:['Drake', 'Derp', 'Derek', 'Dominique']DrakeDerpAdding and removing itemsWe can use the functions append() and remove() to manipulate the list.

10 #!/usr/bin/pythonl = [ "Drake", "Derp", "Derek", "Dominique" ]print l # prints all ("Victoria") # add l # print all ("Derp") # remove ("Drake") # remove l # print all :['Drake', 'Derp', 'Derek', 'Dominique']Page 12 Python Beginner Tutorials - 24th July 2015 View online at ['Drake', 'Derp', 'Derek', 'Dominique', 'Victoria']['Derek', 'Dominique', 'Victoria']Sorting listsWe can sort the list using the sort() function.#!/usr/bin/pythonl = [ "Drake", "Derp", "Derek", "Dominique" ]print l # prints all () # sorts the list in alphabetical orderprint l # prints all elementsOutput:['Drake', 'Derp', 'Derek', 'Dominique']['Derek', 'Derp', 'Dominique', 'Drake']If you want to have the list in descending order, simply use the reverse() function.


Related search queries