This topic contains 0 replies, has 1 voice, and was last updated by  utterz 2 months, 3 weeks ago.

Viewing 1 post (of 1 total)
  • Author
  • #716


    In this post we will be looking at the very basics of programming in python. Python is an excellent beginner programming language. It is easy to read and can make use of lots of different library’s allowing you to code basic computer programs, bots, websites and even can allow you to make super advanced machine learning programs.
    Python numbers

    Calculations in python are written just like they are on a normal calculator for example

    >>> 3+4
    >>> 3*3
    >>> 9*0
    >>> 00.2*2
    >>> 8+3*2
    >>> 18/4
    >>> 18//4 #Using two // rounds the number down to the nearest whole number.
    >>> 5*5*5*5
    >>> 5**3 #Easier way of calculating power numbers

    >>> apple =4 #These are variables and can store data which then can be added together with other variables.
    >>> orange = 3
    >>> apple+orange
    #Basic “Strings” in python

    >>> ‘string’ #A string can be contained within two ”
    >>> “hello my name is james” #You can also contain a string in two “” instead
    ‘hello my name is james’
    >>> ‘I do\’nt like pie’ #If you have a ‘ in your string you must escape it by placing a \ in front of it so python doesn’t get confused.
    “I do’nt like pie”

    #First function to print string use print function and place string.
    >>> print(“hey there people”)
    hey there people

    #You can also add strings together for example:
    >>> firstName =”james ” #Note the space added to end of string else first and last name will be merged together
    >>> lastName =”marcus”
    >>> firstName+lastName
    ‘james marcus’
    >>> firstName *5 #This will display the first name 5 times!
    ‘james james james james james’

    >>> user =”James Howard”
    >>> user[5] #this gets the 5th character in a string Computer start counting at 0 so for example 0 will be J 1 will a… etc. A blank space will also count a character, so fetching the fifth character will show a blank space.
    ‘ ‘
    >>> user[-1] #if you want to fetch the last character of a file use this function
    >>> user[-4] #If you want to fetch the fourth last character use this.
    >>> user[2:7] #This code will fetch all characters from the second character up to the seventh character.
    ‘mes H’
    >>> user[::7] #if you want to echo out the first character with the seventh character use this.
    >>> user[:5] #this will fetch the characters from the start to the fifth character.
    >>> user[2:] #this will fetch the characters starting from the second character to the end of the string.
    ‘mes Howard’

    #Using this function will help you find the character length of a string.
    >>> len(‘ffregfrgreg44rffgttrt’)
    #You can input a variable into the function to count the number of charterers in a string stored by that variable.
    >>> len(user)
    Python Lists

    Lists in python are very important and are very easy to do!

    >>> Numberlist = [12, 22, 33, 11, 18] #This will create a list of different numbers

    >>> Numberlist [2] #This will fetch the thrid item on the list, remember that the computer starts counting at 0.


    >>> Numberlist[2]=39 #You can temporary change a number in the list by using this code.

    >>> Numberlist + [1000,1002,10004] #You can then temporary append extra numbers to your list using this code.

    [12, 22, 39, 11, 18, 1000, 1002, 10004]

    >>> Numberlist.append(10000) #To permanently append extra numbers onto your list which will not get overwritten use .append

    >>> Numberlist

    [12, 22, 39, 11, 18, 10000]

    >>> Numberlist[:2] #This will fetch the first two items in the list.

    [12, 22]

    >>> Numberlist [:2] =[0,0] #This will change the the first two items in the list to 0

    >>> Numberlist

    [0, 0, 39, 11, 18, 10000]

    >>> Numberlist [:2] = [] #This will delete the first two items in the list forever!

    >>> Numberlist

    [39, 11, 18, 10000]

    >>> Numberlist[:] =[] #This code will fetch all characters from beginning to end and will then set them to nothing deleting everything.

    >>> Numberlist #As you can see nothing is returned.


Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.