Python, get sub string

If you want to get sub string from a string so you can easily do this by getting slice, in Python. In Python, there is no built-in Substring function like in Java (str.substring) or any other language. Instead, Python relies on slice technique. Slice technique required two parameters in squire brackets using string object, first is the starting index from where we need string, and second parameter indicate how many character you want to retrieve, this second parameter is optional if you do not pass second parameter then it consider you required all the characters from the given index (first parameter). example is mentioned below: Code


	str = "Hello, Python Programmers"

	# From index 0 to 5 (not including 5)
	sub_string1 = str[0:5] 
	Print(sub_string1) # print: Hello

	# From index 10 to end
	sub_string2 = str[10:]
	Print(sub_string2) # print: Programmers

	# From start to index 5
	sub_string3 = str[:5]
	Print(sub_string3) # print: Hello
}