Amatör olarak Python kodlamaya devam ediyorum. En son dosya okuma işlemleri ile alakalı bir örnek yapmıştım.
İki dosya içeriğini okuyup karşılaştırdıktan sonra farklı olan kısımları ekrana yazan bir örnekti.
Burda önemli olan fonksiyonlar:
- Dosyayı açmak için open() fonksiyonu,
- Dosyadan satır satır veri okumak için readlines() metodu
- Dosyayı kapamak için close() metodu
Bu fonksiyonların kullanımını bildikten sonra geriye kalanlar kodun temel kullanından ibaret olan şeylerdir: if yapısı, for yapısı, print() fonksiyonu vs.
Bugün biraz print() fonksiyonundan bahsedeceğim. Çok ayrıntıya girmeden genel hatlarına değineceğim.
print() fonksiyonu ile birden fazla veriyi yazdırabilirsiniz. Bunun için verilerin aynı tipte olması gibi bir zorunluluk bulunmaktadır.
Birden fazla ve farklı veri tipini yazdırma
Elimizde string, int ve float tipinde veriler olsun. Aşağıdaki gibi tanımlamalarını yaptıktan sonra tek satırda yazdıralım.
Kodun çıktısı aşağıdaki gibidir :
Görüldüğü gibi virgül ile ayrılan her veri tipi yan yana aralarına boşluk gelecek şekilde yazıldı.
Burada olay boşluk karakterinin print() fonksiyonunda default ayırıcı olması. Tabi bunu bir parametre ile değiştirebiliriz :
serp parametresi ile istediğimiz karakteri ayıraç olarak kullanabiliriz.
Ayrıca print() fonksiyonunu kullanarak stil verecek şekilde de çıktı alabiliriz. Örnek üzerinden gidelim:
Örnekte olduğu gibi format() fonksiyonunu kullanarak bir metin içerisinde istediğimiz gibi verileri ayarlayabiliriz. Bu kodun çıktısı aşağıdaki gibidir :
Ayrıca eğer print() fonksiyonunun içerisindeki veriler string ise "+" operatörü ile stringleri birleştirebiliriz.
Son olarak da * karakteri önemli. print() fonksiyonu içerisinde yıldız karakterini görelim :
Bu kodun çıktısı ise aşağıdaki gibidir :
Görüldüğü gibi yıldız karakteri bir stringi parçalara ayırıyor.
Şimdilik bu kadar. Programı farklı alternatifler deneyerek test edebilirsiniz.
I appreciate your upvotes and support
Congratulations @bpn! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You got a 100.00% promotion boost from @shares courtesy of @addo.sports! Thank you for following @Shares rules of promoting your articles.
Have a nice day.
@Shares - Keep steeming good articles to help Steem network grow.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You got a 100.00% upvote from @whalepromobot courtesy of @addo.sports!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You got a 33.33% upvote from @redlambo courtesy of @addo.sports! Make sure to use tag #redlambo to be considered for the curation post!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This post has received a $100.00 % upvote from @siditech thanks to: @addo.sports.
Here's a banana!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You got a 33.33% upvote from @bid4joy courtesy of @addo.sports!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for using @sleepagent bid bot serves.
This post has received a 50 % upvote from @sleepagent.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
you just rose a upvote from @curationhelper thanks for post promotion.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit