Aug 27, 2018
C++ Basics and Python
Python
dictionary get() Method
get() MethodThe method get() returns a value for the given key. If key is not available then returns default value None.
dict.get(key, default = None)key − This is the
Keyto be searched in the dictionary.default − This is the
Valueto be returned in case key does not exist.
dict = {'Name': 'Zabra', 'Age': 7}
print "Value : %s" % dict.get('Age')
print "Value : %s" % dict.get('Education', "Never")Output:
Value : 7
Value : NeverC++
abs()
abs()Returns the absolute value of parameter n .
std::tolower(charT c, const locale& loc)
std::tolower(charT c, const locale& loc)Converts parameter c to its lowercase equivalent if c is an uppercase letter and has a lowercase equivalent, as determined by the ctype facet of locale loc. If no such conversion is possible, the value returned is c unchanged.
std::string::erase()
std::string::erase()Erases part of the string, reducing its length
sequence: Erases the portion of the string value that begins at the character position
posand spanslencharacters (or until the end of the string, if either the content is too short or iflenis string::npos. Notice that the default argument erases all characters in the string (like member function clear).character: Erases the character pointed by
p.range: Erases the sequence of characters in the range
[first,last).
std::string::substr()
std::string::substr()Returns a newly constructed string object with its value initialized to a copy of a substring of this object.
The substring is the portion of the object that starts at character position pos and spans len characters (or until the end of the string, whichever comes first).
pos
Position of the first character to be copied as a substring. If this is equal to the string length, the function returns an empty string. If this is greater than the string length, it throws out_of_range. Note: The first character is denoted by a value of
0(not 1).
len
Number of characters to include in the substring (if the string is shorter, as many characters as possible are used). A value of string::npos indicates all characters until the end of the string.
Last updated