DEV Community

Cover image for Learning GO: 04 - Printing Strings
Gaurav Vala
Gaurav Vala

Posted on • Edited on

1

Learning GO: 04 - Printing Strings

Hey! I am Currently learning Go Lang, and I am taking some basic Notes on my Notion and though I'd also just publish them here. They are not well thought out or well written but it's just me taking notes from time to time for my reference.

I am taking the Udemy Course by Maximilian Schwarzmüller,


Notes

We can format the Output Strings with Printf() Method

  • there are different option to add to the output string that can format it
  • here we have %v and \n that helped to add the variable value and also with \n everything after it will be on next line
  • There are many of these “verbs that we can add to format, check the official docs
  • We can use %.0f to round the floating numbers
  • the number before f refers to the number we wanna show after the .

- so if we say %.2f that will print 2 number after .

fmt.Printf("Future Value : %v\nFuture Value (Adjusted for Inflation): %v", futureValue, futureRealValue)
Enter fullscreen mode Exit fullscreen mode

Storing Formatted strings into a variable

  • using the method Sprintf() we can store any formatted string into a variable and then use that variable instead of whole string
formattedFV := fmt.Sprintf("Future Value : %.0f\n", futureValue)
formattedFRV := fmt.Sprintf("Future Value (Adjusted for Inflation): %0.f\n", futureRealValue)
Enter fullscreen mode Exit fullscreen mode
  • after that we can use the Print() method to print these strings which will just print the string without any formatting
fmt.Print(formattedFV, formattedFRV)
Enter fullscreen mode Exit fullscreen mode

Multi line Strings

  • We can use backticks `` instead of double quotes to create multiline formatted string, this way

`go
fmt.Printf(`Future Value : %v Future Value (Adjusted for Inflation): %v`, futureValue, futureRealValue)
`

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay