Skip to main content

Posts

Showing posts from February, 2020

Printing pattern A using A's and * 's

Printing pattern A using A's We are going to write our first pattern program in python. Printing pattern A using A's is much simple in python as compare to any other programming language. We will simply be using for loop and if-else statement for constructing a pattern A. Here is the code of how you will do that. # Program to print a pattern A using A's str= " " var= "A" j= 1 for i in range ( 10 , 0 , - 1 ): print (str* 85 , end = "" ) print (str*i+var , end = "" ) if i== 10 : continue elif i== 4 : print (str+var+str+var+str+var+str+var+str+var+str+var+str) j=j+ 2 else : print (str*j+var) j=j+ 2 Output: A A A A A A A A A A A A A A A A A A A A A A          Printing pattern A using *'s Now, lets directly see t...

String methods in python

Python String Methods Python has very large set of in-built functions in strings which we can use directly without writing any extra code. Note: We can store the result after applying methods into variables. There will be no change in the original string after applying these methods. We will the methods step by step with examples. 1.) capitalize()       It capitalizes the first letter of our string.       eg.  str = "i am a word" m=str.capitalize() print (m) Output: I am a word 2.) casefold()       It  converts the characters of string into lowercase. eg. str = "SUN RISES IN EAST" m=str.casefold() print (m) Output: sun rises in east 3.) count()        It returns the count of character that is passed. eg. str = "Betty bought a bit of butter, But the butter was so bitter, So she bought some better butter, To make the bitter butter better" m...

String Slicing in python

String Slicing Python  Slicing refers to extracting some words from a string. As in many other languages there are many different concepts for extracting a letters or words from a string ,in python we are having the concept of slicing. We can also the same things using looping, we will learn about it in our next tutorials. Indexing in Strings Before starting slicing, we need to understand the indexing in python. We have the concept of positive indexing  and  negative indexing.  Positive indexing starts from 0 to (length of string).It goes from forward to backward. Negative indexing starts from -1 to -(length of string + 1). It is illustrated in below example Below are some examples of how to use string slicing to extract characters from string. Accessing the characters in a string using positive index eg. string= "We are studying string slicing" s=string[ 0 ] # A single character will be printed present at index 0 w=string[ 4 ] # A...