//different methods to take a string from user #include <stdio.h> int main () { char str1 [ 10 ]; printf ( "enter a string:" ); gets ( str1 ); //method 1: using gets function printf ( " %s \n " , str1 ); char str2 [ 10 ]; printf ( "enter a string:" ); scanf ( " %s " ,& str2 ); //method 2:using scanf, but with this we cannot use white spaces in string printf ( " %s \n " , str2 ); printf ( "using puts displaying string output \n " ); puts ( str2 ); //puts function is used to display string output return 0 ; }
'''class person: def __init__(self,fname,lname): self.fname=fname self.lname=lname self.fullname=f"{self.fname} {self.lname}" #derived from above attributes not from object arguments p1=person("N","Harish") #object print(p1.fullname) p1.fname="software" #here i can change fname and lname print(p1.fname) print(p1.fullname) #fname changed but full name was not changed because it is not came from object arguments ''' #_______________________________________________________________________ # using property decorator we change directly the attribute see below code class person: def __init__ ( self , fname , lname): self .fname=fname self .lname=lname @property #due to this i can call fullname function as attribute that is without () after function def fullname ( self ): #getter if self .fname== None or self .lname== None : return "fullname was dele...
#raise is a built-in keyword used to raise exception # visit all built-in Exceptions and understand name= input ( "enter u r name:" ) if name.isnumeric(): raise Exception ( "numbers r not allowed" ) #here we used raise keyword
Comments
Post a Comment