Home  >  Article  >  Backend Development  >  Learning GO: 03

Learning GO: 03

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-06 14:07:03163browse

Learning GO: 03

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

User Input

  • Getting values from users through cli is pretty similar to how it is done in C language
  • we can use the Scan() method of the fmt package to do that.

fmt.Scan(&investmentAmount) 


  • here the investmentAmount is already declared and it has a value in it so to override that we are using the “&” symbol, which is a pointer to the actual variable and here will override the value from user input
  • If user dont give any value to the variable, it will be initialized with the default value of the type, for float it will be 0.0

Declaring Variables without initial value

  • We can declare a variable without initializing any value to that variable, but for that, we will need to explicitly declare the type of the variable, which required as GO Lang is a statically typed language
  • This will be declared using the var keyword and then the variable name and then the type of variable

var years float64
var expectedReturn float64


All Methods to declare variables in GO Lang


const inflationRate = 2.5
var investmentAmount float64 = 1000
var years float64
expectedReturn := 5.5


The above is the detailed content of Learning GO: 03. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn