0% found this document useful (0 votes)
45 views

Functions and Working

This document provides information on various Python concepts like strings, lists, maps, and loops. It explains that: 1. Backslashes are used to continue strings onto the next line. The %s operator embeds values into strings. Lists can be accessed and modified using indexes, append, delete, concatenation and repetition operations. 2. Maps allow accessing, modifying, and adding key-value pairs. The turtle module can be used to draw graphics and shapes. Functions like int(), str(), and float() convert between string and number data types. 3. Range creates an iterator for a set of numbers. The break keyword exits a loop immediately, while the end argument for print specifies what is

Uploaded by

Junaid Mahsud
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Functions and Working

This document provides information on various Python concepts like strings, lists, maps, and loops. It explains that: 1. Backslashes are used to continue strings onto the next line. The %s operator embeds values into strings. Lists can be accessed and modified using indexes, append, delete, concatenation and repetition operations. 2. Maps allow accessing, modifying, and adding key-value pairs. The turtle module can be used to draw graphics and shapes. Functions like int(), str(), and float() convert between string and number data types. 3. Range creates an iterator for a set of numbers. The break keyword exits a loop immediately, while the end argument for print specifies what is

Uploaded by

Junaid Mahsud
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Function Working

Strings
Backslash (\) Used before single or double quote when the string is started with
single or double quote respectively to let python know the string is
still continued
%s Embed values in a string
Lists
list_name[index position] Printing this will print the specified index number item in the list
and the index number starts from 0. And making it equal to
another value would replace that index position value with the
other one. We can have a subset of the list by placing a colon ( : )
in index position to give a range. E.g [0:3]
List_name.append(xxxxx) Append function is used to add values in the list at the end of the
list.
del list_name[index position] To delete the specified index position item from the list

List1+list2 To join or add together two lists


List_name*any number To repeat the list the number of times it is multiplied with the
number
Maps
Map_name[‘Key’] To access the value of the key in the created map
del map_name[‘Key’] To delete the mentioned key from the created map
Map_name[‘Key’]=’New value’ To replace the value of the key
Map_name.update({‘key’:’value’}) To add another key to the map
Turtle
import turtle To import turtle module
Anyvariable=turtle.Pen() To open the canvas to draw on
Anyvariable.forward(distance) To move the turtle forward the mentioned distance
Anyvariable.left(angle) To rotate the turtle left according to the specified angle
anyvariable.reset() To erase the canvas
anyvariable.clear() To erase the canvas and leave the cursor wherever it is
t.up() To stop drawing and just move the cursor if we want to
t.down() To start drawing/put the pen down again

int(‘10’) Converts the string into number(integer)


str(14) Converts the number into string
float(’10.5’) It can convert even decimal strings into numbers
range(0,5) Range acts as an iterator i.e the number of times the value would
repeat in this case it would repeat 5-0=5 times
Loops
Break We use the break keyword to exit the loop. The break keyword is a
way of jumping out of a loop(in other words, stopping it)
immediately and it works with both while and for loops
Page# 76 of Python for kids book.
end= It’s a keyword argument for the print() function. The end=
keyword argument dictates what should be printed after all of the
arguments have been printed.
>>>for i in range(10):
print(i, end=’ ‘)
result will be
0123456789

The above end= argument causes a space to be printed after each


number, rather than the default newline character.

You might also like