logo

Kalenderfuncties in Python | Stel 1( kalender(), maand(), isleap()...) in

Python definieert een ingebouwde module ' kalender ' die bewerkingen met betrekking tot de kalender afhandelt.
Operaties aan de kalender: 
1. kalender(jaar w l c) : - Deze functie geeft het jaar en de breedte van de tekens weer. aantal regels per week en kolomscheidingen.
2. eersteweekdag() : - Deze functie retourneert de nummer van de eerste weekdag . Standaard 0 (maandag).
 

javateerbaar
Python3
# Python code to demonstrate the working of # calendar() and firstweeksday() # importing calendar module for calendar operations import calendar # using calendar to print calendar of year # prints calendar of 2012 print ('The calendar of year 2012 is : ') print (calendar.calendar(2012216)) #using firstweekday() to print starting day number print ('The starting day number in calendar is : 'end='') print (calendar.firstweekday()) 

Uitgang: 
 



The calendar of year 2012 is : 2012 January February March Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 1 2 3 4 5 1 2 3 4 2 3 4 5 6 7 8 6 7 8 9 10 11 12 5 6 7 8 9 10 11 9 10 11 12 13 14 15 13 14 15 16 17 18 19 12 13 14 15 16 17 18 16 17 18 19 20 21 22 20 21 22 23 24 25 26 19 20 21 22 23 24 25 23 24 25 26 27 28 29 27 28 29 26 27 28 29 30 31 30 31 April May June Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 1 2 3 4 5 6 1 2 3 2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10 9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17 16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24 23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30 30 July August September Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 1 2 3 4 5 1 2 2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9 9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16 16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23 23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30 30 31 October November December Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 1 2 3 4 1 2 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9 15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16 22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23 29 30 31 26 27 28 29 30 24 25 26 27 28 29 30 31 The starting day number in calendar is : 0


3. isleap (jaar) :- Deze functie controleert of het in het argument genoemde jaartal dat is A sprong of niet .
4. schrikkeldagen (jaar1 jaar2) : - Deze functie retourneert de aantal schrikkeldagen tussen de opgegeven jaren bij argumenten.
 

Python3
# Python code to demonstrate the working of # isleap() and leapdays() # importing calendar module for calendar operations import calendar # using isleap() to check if year is leap or not if (calendar.isleap(2008)): print ('The year is leap') else : print ('The year is not leap') #using leapdays() to print leap days between years  print ('The leap days between 1950 and 2000 are : 'end='') print (calendar.leapdays(1950 2000)) 

Uitgang: 
 

The year is leap The leap days between 1950 and 2000 are : 12


5. maand (jaar maand w l) :- Deze functie drukt de maand van een bepaald jaar genoemd in argumenten. Er zijn 4 argumenten nodig, de tekenbreedte van het jaar en de maand en nee. aantal lijnen genomen per week .
 



tekenreeksarray c
Python3
# Python code to demonstrate the working of # month() # importing calendar module for calendar operations import calendar # using month() to display month of specific year print ('The month 5th of 2016 is :') print (calendar.month(2016521)) 

Uitgang: 
 

The month 5th of 2016 is : May 2016 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31