indexing python first and last
l = [1,2,3,4,5] l[::len(l)-1]
Here is what the above code is Doing:
1. l[::len(l)-1]
2. l[::4]
3. l[::-1]
4. l[::-1]
5. [5,4,3,2,1]
l = [1,2,3,4,5] l[::len(l)-1]
Here is what the above code is Doing:
1. l[::len(l)-1]
2. l[::4]
3. l[::-1]
4. l[::-1]
5. [5,4,3,2,1]
command=lambda:[funcA(), funcB(), funcC()] Here is what the above code is Doing: 1. Create a function that does something 2. Create a button that calls the function 3. Create a button that calls multiple functions
# Play with turtle and random modules import turtle import random sc = turtle.Screen() t = turtle.Turtle() sc.setup(800,600) sc.title(“setup”) t.pensize(3) t.speed(0) # Drawing diff circles with random radius in diff positions , Range(-200,200) for n in range(100): color = [“red”, “green”, “blue”, “purple”, “yellow”, “orange”, “black”] t.pencolor(random.choice(color)) t.penup() t.goto(random.randint(-200,200), random.randint(-200,200)) t.pendown() t.circle(random.randint(0,20)) sc.exitonclick() Here is…
import seaborn as sns Here is what the above code is Doing: 1. Importing the seaborn library as sns.
list1 = [1, 2, 4] list2 = [4, 5, 6] set_difference = set(list1) – set(list2) list_difference = list(set_difference) print(list_difference) #result [1,2] Here is what the above code is Doing: 1. We create two lists, list1 and list2. 2. We convert both lists to sets using the set() function. 3. We use the – operator to…
string = str(input(“Your name:- “)).upper() print(string) Here is what the above code is Doing: 1. It’s taking input from the user and storing it in a variable called string. 2. It’s converting the input to upper case. 3. It’s printing the input.
>>> s = ‘hello’ >>> s.rfind(‘l’) 3 Here is what the above code is Doing: 1. We create a string variable called s and set it equal to ‘hello’. 2. We call the rfind() method on the string variable s. 3. We pass in the string ‘l’ as an argument to the rfind() method. 4….